Skip to content

Commit e3183d6

Browse files
authored
fix (pino): do not fallback to empty string "message" if none given (#75)
Now that "message" is optional in the ecs-logging spec, we can drop the fallback to an empty string message added in #64. Fixes: #73
1 parent 44549fa commit e3183d6

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

loggers/pino/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
# @elastic/ecs-pino-format Changelog
22

3+
## Unreleased
4+
5+
- The ecs-logging spec was [updated to allow "message" to be
6+
optional](https://github.com/elastic/ecs-logging/pull/55). This allows the
7+
[change to fallback to an empty string message](https://github.com/elastic/ecs-logging-nodejs/pull/64)
8+
to be removed -- which is cleaner and fixes a
9+
[side-effect bug](https://github.com/elastic/ecs-logging-nodejs/issues/73)
10+
where usage of pino's `prettyPrint: true` was broken.
11+
312
## v1.1.0
413

514
- Fix a "TypeError: Cannot read property 'host' of undefined" crash when using
615
`convertReqRes: true` and logging a `req` field that is not an HTTP request
716
object.
17+
([#71](https://github.com/elastic/ecs-logging-nodejs/pull/71))
818

919
- Set the "message" to the empty string for logger calls that provide no
1020
message, e.g. `log.info({foo: 'bar'})`. In this case pino will not add a
1121
message field, which breaks ecs-logging spec.
22+
([#64](https://github.com/elastic/ecs-logging-nodejs/pull/64))
1223

1324
- Fix handling when the [`base`](https://getpino.io/#/docs/api?id=base-object)
1425
option is used to the pino constructor.
26+
([#63](https://github.com/elastic/ecs-logging-nodejs/pull/63))
1527

1628
Before this change, using, for example:
1729
const log = pino({base: {foo: "bar"}, ...ecsFormat()})

loggers/pino/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,6 @@ function createEcsPinoOptions (opts) {
213213
}
214214
}
215215

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-
222216
return ecsObj
223217
}
224218
}

loggers/pino/test/basic.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ test('ecsPinoFormat cases', suite => {
133133
}
134134
},
135135
{
136-
name: 'no message in log call should result in empty string message',
136+
name: 'no message in log call should be fine',
137137
pinoOpts: ecsFormat(),
138138
loggingFn: (log) => {
139139
log.info({ foo: 'bar' })
@@ -143,8 +143,7 @@ test('ecsPinoFormat cases', suite => {
143143
ecs: { version: ecsVersion },
144144
process: { pid: process.pid },
145145
host: { hostname: os.hostname },
146-
foo: 'bar',
147-
message: ''
146+
foo: 'bar'
148147
}
149148
}
150149
]

0 commit comments

Comments
 (0)