-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting message to empty string breaks formatting with pino-pretty #73
Comments
@jdelight Thanks for the ticket! Interesting. According to https://getpino.io/#/docs/api?id=message-string the "message" argument in a log statement should win over a message attribute on the
That is based on the test whether the "message" argument is However, the logic for deciding if a "message" argument wins in I think I'd call this a bug in pino's In the meantime, I'm sorry this breaks your use case. If reasonable for your usage, I have a start at a pretty-printer alternative to FWIW, here is my potential fix to pino:
|
Thanks @trentm - that all makes sense. I'll keep a look out for any further discussions on pino/pino-pretty. In the meantime I've wrapped the formatter.log to remove the message key. But will update if a fix (like yours above) is implemented. |
I'll follow through on that pino PR. However, with elastic/ecs-logging#55 I think we'll remove the requirement that ecs-logging records have a "message" field. Once that is in, I can drop the setting of the fallback empty string for "message". That'll solve this issue. |
@jdelight @elastic/ecs-pino-format@1.1.1 is published, which should have the fix for you. |
That's awesome - thanks @trentm 👍 |
Hey there, I've just updated to version 1.1.0 (pino ) and it seems the change to set an empty message property breaks formatting.
I'm also using pino-pretty to format logs.
The issues seems to be here:
lastObj
is passed to the ecs log formatter which then sets a message property on it to empty stringthe comment about the line above indicates the message as empty string is set because a message is not present on the object. However, from the code above, message has been separated from the rest of the log object and is not passed into the log formatter at all.
Also from the description of how the log formatter works - the message is intentionally not passed in.
The end result is that when the if statement runs
if (lastMsg && formattedObj && !formattedObj.hasOwnProperty(messageKey)) {...}
it always returns true becauseformattedObj
now does have amessage
property.Simple test case:
using the examples/express-simple.js in this repo - install pino-pretty and set
prettyPrint: true
on the logger config:then when running
node express-simple.js
you should see something like this (note message regarding the server listening is missing):I'm not 100% sure if this is a pino-pretty issue or an ecs format issue - but the update to 1.1.0 seems to have broken what was working so thought I'd raise it here.
The text was updated successfully, but these errors were encountered: