Node-bunyan: Omit specific fields like hostname

Created on 29 Oct 2012  路  5Comments  路  Source: trentm/node-bunyan

My log output is overly verbose and I would like to reduce the included metadata, but it's not clear to me how to omit hostname, pid, etc. Could included fields be made configurable?

[2012-10-29T21:55:53.087Z] INFO: myLogger/86281 on hostname.local (/Users/me/dev/src/project/server/dao.js:235 in bigMethodName): something happened

If fields are configurable, could that be documented more clearly?

Most helpful comment

For those reading this issue, you can omit any fields by hack / overriding the Logger.prototype._emit method, as described here.

All 5 comments

@wachunga Do you mean to remove 'hostname.local' from the output of the bunyan _CLI_? Or to elide that from the JSON objects in the raw Bunyan log files?

If the former then you could consider the 'short' output format:

$ bunyan foo.log -o short
22:56:52.856Z  INFO myservice: My message
    extra: multi
    line
22:56:54.856Z ERROR myservice: My message
...

Eventually I'd like to support plugins there for alternative outputs (somewhat covered in https://github.com/trentm/node-bunyan/issues/9) and possibly make the output format configurable via a "~/.bunyanrc" file or similar.

If the latter, then no. I don't want the hostname field in the raw JSON objects to be optional and still have it be a "Bunyan" log record.

Does that answer your Q?

@trentm Yes, I just meant the output of the CLI; somehow I missed the -o parameter.

The short format isn't quite what I was looking for (I'd like a little more info, eg keep the file, line number and method name) but it's close enough. A .bunyanrc would be very handy.

Thanks for the great library.

'short' format dropping the 'src' info (filename, method, line) is a bug. That needs to be added back. It was just an oversight. https://github.com/trentm/node-bunyan/issues/50

I know it has been a long time but I ended up here because people at our company wanted to see nicer message in bunyan logs and suppress some fields. So taking inspiration from @mpareja 's comment here, I created this small package - tunyan.

This is a first draft and I will keep updating it, hope it helps someone.

For those reading this issue, you can omit any fields by hack / overriding the Logger.prototype._emit method, as described here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shaucorp picture shaucorp  路  5Comments

JustinMcConnell picture JustinMcConnell  路  9Comments

mouhong picture mouhong  路  6Comments

simonexmachina picture simonexmachina  路  8Comments

raybooysen picture raybooysen  路  3Comments