node-bunyan icon indicating copy to clipboard operation
node-bunyan copied to clipboard

Customize the message field name

Open mickaeltr opened this issue 9 years ago • 10 comments

My application logs are sent to a SaaS that requires a message field (instead of msg). Is there any way to customize this? Thanks

mickaeltr avatar Nov 06 '15 14:11 mickaeltr

+1

susomartinez avatar Nov 06 '15 14:11 susomartinez

Same question. I would love to customize the output having msg to message mainly and maybe removing some "standard" field.

ygrenzinger avatar Jan 13 '16 10:01 ygrenzinger

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.

trentm avatar Jan 24 '16 01:01 trentm

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

oryagel avatar Dec 07 '16 18:12 oryagel

same here. Anyone managed to solve this?

viniciusgama avatar Aug 10 '18 04:08 viniciusgama

You could try pino

jbunton-atlassian avatar Aug 10 '18 04:08 jbunton-atlassian

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.

gkrinc avatar Oct 19 '18 15:10 gkrinc

Any news on this?

SebTVisage avatar Oct 10 '22 16:10 SebTVisage

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!

image

ojizero avatar May 16 '23 20:05 ojizero

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

SebTVisage avatar May 17 '23 08:05 SebTVisage