Using express with Bunyan (logs)

Asked

Viewed 12 times

0

I created a logger with two streams for two different apps as an example:

const bunyan = require('bunyan');
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');

class bunyanLogger {
    constructor(){
        this.log = bunyan.createLogger({
            name:"MainLogger", 
            streams: [{
                stream: process.stdout, level: 'info'
            },
            this.loggingBunyan.stream('info'),
            ]
        });

        this.log.addStream({
            name: "app1",
            stream: process.stderr,
            level: "info"
        });

        this.log.addStream({
            name: "app2",
            stream: process.stderr,
            level: "info"
        });
    }     
}

module.exports = bunyanLogger;

I need a app.use() in my app.js to receive information from res of the controllers and send as log. Before was using the log4js, whose documentation already teaches how to make such a connection with express. It is not the case of Bunyan, so I need help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.