@@ -22,12 +22,13 @@ export class LogEcs extends Log {
22
22
timestamp : 'iso'
23
23
} )
24
24
this . serializers = { ...ecsSerializers , ...serializers }
25
- this . toJson = toJson
25
+ const [ extra ] = name . split ( ':' )
26
+ this . _extraName = extra
27
+ this . toJson = this . _toJson
26
28
}
27
29
28
30
/* c8 ignore next 18 */
29
31
_applySerializers ( obj ) {
30
- const name = this . name
31
32
const ecsObj = { }
32
33
for ( const key in obj ) {
33
34
const value = obj [ key ]
@@ -39,48 +40,50 @@ export class LogEcs extends Log {
39
40
this . serializers [ key ] ( value , ecsObj )
40
41
} else {
41
42
// add all other unknown fields to extra
42
- ecsObj . extra = ecsObj . extra || { [ name ] : { } }
43
- ecsObj . extra [ name ] [ key ] = value
43
+ const extra = this . _extraName
44
+ ecsObj . extra = ecsObj . extra || { [ extra ] : { } }
45
+ ecsObj . extra [ extra ] [ key ] = value
44
46
}
45
47
}
46
48
}
47
49
return ecsObj
48
50
}
49
- }
50
-
51
- LogEcs . serializers = ecsSerializers
52
51
53
- function toJson ( obj , serializers ) {
54
- const { level, time, name, msg, pid, hostname, diff, ...other } = obj
52
+ _toJson ( obj , serializers ) {
53
+ const { level, time, name, msg, pid, hostname, diff, ...other } = obj
55
54
56
- const ecsObj = {
57
- log : {
58
- level,
59
- logger : name ,
60
- diff_ms : diff
61
- } ,
62
- message : msg ,
63
- '@timestamp' : time ,
64
- process : pid ? { pid } : undefined ,
65
- host : hostname ? { hostname } : undefined
66
- }
67
-
68
- for ( const key in other ) {
69
- const value = other [ key ]
70
- if (
71
- value === undefined ||
72
- ! Object . prototype . hasOwnProperty . call ( other , key )
73
- ) {
74
- continue
55
+ const ecsObj = {
56
+ log : {
57
+ level,
58
+ logger : name ,
59
+ diff_ms : diff
60
+ } ,
61
+ message : msg ,
62
+ '@timestamp' : time ,
63
+ process : pid ? { pid } : undefined ,
64
+ host : hostname ? { hostname } : undefined
75
65
}
76
- if ( serializers [ key ] ) {
77
- serializers [ key ] ( value , ecsObj )
78
- } else {
79
- // add all other unknown fields to extra
80
- ecsObj . extra = ecsObj . extra || { [ name ] : { } }
81
- ecsObj . extra [ name ] [ key ] = value
66
+
67
+ for ( const key in other ) {
68
+ const value = other [ key ]
69
+ if (
70
+ value === undefined ||
71
+ ! Object . prototype . hasOwnProperty . call ( other , key )
72
+ ) {
73
+ continue
74
+ }
75
+ if ( serializers [ key ] ) {
76
+ serializers [ key ] ( value , ecsObj )
77
+ } else {
78
+ // add all other unknown fields to extra
79
+ const extra = this . _extraName
80
+ ecsObj . extra = ecsObj . extra || { [ extra ] : { } }
81
+ ecsObj . extra [ extra ] [ key ] = value
82
+ }
82
83
}
83
- }
84
84
85
- return stringify ( ecsObj )
85
+ return stringify ( ecsObj )
86
+ }
86
87
}
88
+
89
+ LogEcs . serializers = ecsSerializers
0 commit comments