How can Bunyan be used to save logs into a specific file?

6.3k views Asked by At

My NodeJS app is acting buggy and I want to properly log everything that is happening while it is being used.

I came across Bunyan and it looks great. Except, like all other "loggers" it simply prints to stdout which makes it very hard for me to properly analyse what is going on.

Is there any way I can get Bunyan to always output to some file logs.json for example?

1

There are 1 answers

3
AudioBubble On BEST ANSWER

You should log even if your app is not buggy. Anyway, did you actually read the documents? You use a stream:

var bunyanOpts = {
    name: 'myapp',
    streams: [
    {
        level: 'debug',
        stream: process.stdout       // log INFO and above to stdout
    },
    {
        level: 'info',
        path: '/var/tmp/logs.json'  // log ERROR and above to a file
    }
  ]
};

var logger = Bunyan.createLogger(bunyanOpts);

Now to view the log:

$ tail -f /var/tmp/logs.json | bunyan -o short