Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable logging for all streams #456

Closed
CodisRedding opened this issue Oct 29, 2016 · 1 comment
Closed

disable logging for all streams #456

CodisRedding opened this issue Oct 29, 2016 · 1 comment

Comments

@CodisRedding
Copy link

CodisRedding commented Oct 29, 2016

I've seen talk of this throughout the Issues, but I don't see a solution. Is there a way to disable logging? I don't want to log when testing.

currently I'm disabling like this but it seems hacky

// logger.js
const config = require('./config');

/*
 * LEVEL HIEARCHY
 *  disable: > 60
 *  fatal  :60
 *  error  :50 -- logs everythig above
 *  warn   :40 -- logs everythig above
 *  info   :30 -- logs everythig above
 *  debug  :20 -- logs everythig above
 *  trace  :10 -- logs everythig above
 */

const LEVEL_DISABLE = 61;
const DISABLE = config.LOG_DISABLE;

module.exports = require('bunyan').createLogger({
  name: config.SERVICE_NAME,
  streams: [{
    level: DISABLE || config.LOG_STDOUT_DISABLE ? LEVEL_DISABLE : config.LOG_STDOUT_LEVEL,
    stream: process.stdout
  }, {
    level: DISABLE || config.LOG_FILE_DISABLE ? LEVEL_DISABLE : config.LOG_FILE_LEVEL,
    path: config.LOG_FILE
  }]
});
// config.json
{
  "LOG_FILE": "/var/tmp/node-bus-service.log",
  "LOG_FILE_LEVEL": "trace",
  "SERVICE_NAME": "node-bus-service",
  "development": {
    "LOG_DISABLE": true,
    "LOG_FILE_DISABLE": true,
    "LOG_STDOUT_DISABLE": false,
    "LOG_STDOUT_LEVEL": "info"
  },
  "qa": {},
  "test": {}
}
@trentm
Copy link
Owner

trentm commented Nov 8, 2016

@CodisRedding Setting the level to higher than the 'fatal' level is what I'd do. However, I'd probably do something like this:

// ...
if (config.LOG_DISABLE) {
    log.level(bunyan.FATAL + 1)
}

Note that eventually I'd like to have an "off"/bunyan.OFF "level" to more explicitly turn logging off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants