node-bunyan
node-bunyan copied to clipboard
Customize the message field name
My application logs are sent to a SaaS that requires a message
field (instead of msg
).
Is there any way to customize this?
Thanks
+1
Same question. I would love to customize the output having msg to message mainly and maybe removing some "standard" field.
Thanks for the question and sorry for the delays. I'll be making a second pass through the issues to actually triage. Before then a note to myself: I vaguely recall an earlier question where I posed a custom bunyan stream that could effectively do this. TODO: find that again.
Sorry to bump this. I have the same issue of a SaaS that expect a message
field instead of msg
.
Is this possible somehow?
Thanks
same here. Anyone managed to solve this?
You could try pino
I would love to see a way for all standard fields to be modified. Our log levels follow RFC 3164 so it's kind of annoying that we can't change those in bunyan. And like OP our logging system expects message
not msg
and those extra fields create a lot of noise in our logging system.
Would be nice if this could either be done in a stream or serializer, where the final log object could be cloned and modified right before output.
Any news on this?
a possible workaround for this is to override the stream
option when instantiating the logger, example
import * as Bunyan from 'bunyan';
const logger = Bunyan.createLogger({
name: 'app logger',
stream: {
write: (log) => {
const logObject = JSON.parse(log);
logObject.message = logObject.msg;
logObject.msg = undefined;
return process.stdout.write(JSON.stringify(logObject) + '\n');
},
},
});
this may or may not feasible depending on the specific use-case!
Personally, I went for pino instead. This project seems to be dead for 3 years, I don't know why so many projects go for it