Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created August 10, 2011 06:21
Show Gist options
  • Save indexzero/1136240 to your computer and use it in GitHub Desktop.
Save indexzero/1136240 to your computer and use it in GitHub Desktop.

Configuring your log levels to go to different transports in winston

By default winston uses the following levels:

var levels = {
  silly: 0, 
  verbose: 1, 
  info: 2, 
  warn: 3,
  debug: 4, 
  error: 5
};

Each level is an escalating priority, silly being the most meaningless information, and error being the most important. Winston transports are configured with the minimum level to log. That is, messages will only be logged to a transport if the level is greater than or equal to the .level instance variable on the transport object (see: https://github.com/indexzero/winston/blob/master/lib/winston/logger.js#L131-132).

This is considered an intelligent default because it is assumed that the higher priority messages would want to be persisted to the most transports, while the lowest priority may only be persistented to the console. An example of this is in standard-levels.js.

In the event you *don't want this default, see custom-levels.js which configures a Console transport which only logs debug and error messages and Loggly transport which logs all other levels.

var winston = require('winston');
var levels = {
debug: 0,
error: 1,
silly: 2,
verbose: 3,
info: 4,
warn: 5
};
var logglyConfig = {
subdomain: 'your-subdomain',
inputToken: 'your-really-long-input-token',
level: 'silly'
};
var logger = new winston.Logger({
transports: [
new winston.transports.Console({ level: 'error' }),
new winston.transports.Loggly(logglyConfig)
]
});
logger.setLevels(levels);
var winston = require('winston');
//
// The default levels used by winston are below
//
// var levels = {
// silly: 0,
// verbose: 1,
// info: 2,
// warn: 3,
// debug: 4,
// error: 5
// };
//
var logglyConfig = {
subdomain: 'your-subdomain',
inputToken: 'your-really-long-input-token',
//
// The default level for all transports is info
//
level: 'info'
};
var logger = new winston.Logger({
transports: [
new winston.transports.Console({ level: 'silly' }),
new winston.transports.Loggly(logglyConfig)
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment