Search code examples
node.jsbunyan

nodejs bunyan order of elements


I'm using bunyan, and this is an example of what i'm writting in my log.

Is there a way to change the order of the fields printed? from this:

{"name":"appName","hostname":"ip","pid":5817,"level":30,"msg":"message","time":"2015-10-15T19:04:01.596Z","v":0}

To this:

{"time":"2015-10-15T19:04:01.596Z","msg":"message","name":"appName","hostname":"ip","pid":5817,"level":30,"v":0}


Solution

  • Use the bunyan cli to get a more human readable log.

    One option is to pipe just bunyan when you start your app (assuming you are running this from your root directory)

    $ node app.js | ./node_modules/.bin/bunyan
    

    A really short version is to pipe

    $ node app.js | ./node_modules/.bin/bunyan -o short
    

    Search around, there is a lot of power in the bunyan CLI.

    https://github.com/trentm/node-bunyan#cli-usage