Whisher
Whisher

Reputation: 32766

Hapi good logging depends on the enviroment

Is there a way to enable / disable depends on the enviroment in good ?

For instance I'd like to run this only when NODE_ENV is equal to develepement

var goodOptions = {
    opsInterval: 1000,
    reporters: [{
        reporter: require('good-console'),
        events: {log: '*', response: '*' , error: '*' , request: '*'}
    }]
};

server.register({
    register: require('good'),
    options: goodOptions
},
    function(err) {
        if (err) {
            throw err;
        }
    }
);

no ternary operator :)

Upvotes: 0

Views: 444

Answers (1)

Matt Harrison
Matt Harrison

Reputation: 13587

You could just add:

if (process.env.NODE_ENV !== 'development') {
    goodOptions.reporters = [];
}

If you start getting into complex configuration then you should take a look at hapijs/confidence which is a really powerful configuration tool. It would be overkill just for this though.

Upvotes: 2

Related Questions