File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
+ - Set the "message" to the empty string for logger calls that provide no
6
+ message, e.g. ` log.info({foo: 'bar'}) ` . In this case pino will not add a
7
+ message field, which breaks ecs-logging spec.
8
+
5
9
- Fix handling when the [ ` base ` ] ( https://getpino.io/#/docs/api?id=base-object )
6
10
option is used to the pino constructor.
7
11
Original file line number Diff line number Diff line change @@ -213,6 +213,12 @@ function createEcsPinoOptions (opts) {
213
213
}
214
214
}
215
215
216
+ // If no message (https://getpino.io/#/docs/api?id=message-string) is
217
+ // given in the log statement, then pino will not emit a message field.
218
+ // However, the ecs-logging spec requires a message field, so we set
219
+ // a fallback empty string.
220
+ ecsObj . message = ''
221
+
216
222
return ecsObj
217
223
}
218
224
}
Original file line number Diff line number Diff line change @@ -131,6 +131,21 @@ test('ecsPinoFormat cases', suite => {
131
131
ecs : { version : ecsVersion } ,
132
132
message : 'hi'
133
133
}
134
+ } ,
135
+ {
136
+ name : 'no message in log call should result in empty string message' ,
137
+ pinoOpts : ecsFormat ( ) ,
138
+ loggingFn : ( log ) => {
139
+ log . info ( { foo : 'bar' } )
140
+ } ,
141
+ rec : {
142
+ 'log.level' : 'info' ,
143
+ ecs : { version : ecsVersion } ,
144
+ process : { pid : process . pid } ,
145
+ host : { hostname : os . hostname } ,
146
+ foo : 'bar' ,
147
+ message : ''
148
+ }
134
149
}
135
150
]
136
151
You can’t perform that action at this time.
0 commit comments