Node-bunyan: Enable control of the log level via environment variables

Created on 17 Apr 2017  路  2Comments  路  Source: trentm/node-bunyan

It would be useful to be enable control-override of the createLogger level option.

This setting ought to be controlled using environment variables, e.g. BUNYAN_LOG_LEVEL. This way it would be possible to enable different log levels without tracing down every instance of createLogger or leaving it up to the developer to respect the suggested BUNYAN_LOG_LEVEL setting.

Type-Improvement Component-Lib Resolution-WontFix

Most helpful comment

The problem with:

var level = process.env.BUNYAN_LOG_LEVEL || 'info';
var log = bunyan.createLogger({name: 'foo', level: level});

is that you then leave it up to the developers to enforce a consistent standard. Which is fine. On the other hand, modules such as debug focus on standardising conventions, which ... at the level of debugging libraries, has been tremendously useful.

All 2 comments

See #176 for a similar issue. IMO control of logging output streams and levels belongs in the application using Bunyan, and not in the library itself. In #176 I created an example file that shows how the app using Bunyan can control this with environment variables itself: https://github.com/trentm/node-bunyan/blob/master/examples/mute-by-envvars-stream.js

Similar could be done for the log level. Something like:

var level = process.env.BUNYAN_LOG_LEVEL || 'info';
var log = bunyan.createLogger({name: 'foo', level: level});

The problem with:

var level = process.env.BUNYAN_LOG_LEVEL || 'info';
var log = bunyan.createLogger({name: 'foo', level: level});

is that you then leave it up to the developers to enforce a consistent standard. Which is fine. On the other hand, modules such as debug focus on standardising conventions, which ... at the level of debugging libraries, has been tremendously useful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trentm picture trentm  路  5Comments

raybooysen picture raybooysen  路  3Comments

ronkorving picture ronkorving  路  5Comments

trentm picture trentm  路  11Comments

shaucorp picture shaucorp  路  5Comments