First, you instantiate the
LeoWinston container object: the service object which allows you to access all loggers
you create with it.
var LeoWinston = LeoWinston;var leo =levels: silly: 0 debug: 1 verbose: 2 info: 3 warn: 4 error: 5decorate: truepropagate: true;
LeoWinston container options are available:
levels: Log levels to use for all loggers.
Default: uses winston's npm levels;
decorate: Boolean: Whether to decorate each message with the logger name. Default: true
propagate: Boolean: Use log messages propagation?
When propagation is enabled, messages bubble up to parent loggers
When a message is logged with the 'a.b.c.d' logger, it will propagate to loggers 'a.b.c', 'a.b', 'a', and finally, 'root'.
You define loggers with the following method:
name: String: The name of the logger to add.
In order to use propagation, use '.'-notation to qualify logger names.
options: Object?: Logger options object:
propagate: Boolean: Whether messages from this logger propagate further. Default:
When a logger is created with
propagate: false, it will consume the messages without passing them on.
transports: Object: Winston transports configuration. See: Working with transports.
It's required that you have a single logger named
'root': this topmost logger catches messages from all registered
loggers (unless they explicitly define
leo;leo;leo; // no logging, just propagate for nowleo;
It's wise to keep logger options in a config file: this way you'll have flexible app configurations.
After you've configured your loggers, use the following method to get a logger:
If the logger was not defined, it's created as a no-op logger. When propagation is enabled, its messages propagate to the 'root' logger.
Wielding a logger, use it like a normal Winston logger:
var logger = leo;logger; // (level, message[, meta][, callback])// Each log level gets a corresponding methodlogger;logger;logger;logger;logger;logger;
propagation: false, the message propagation stops on it.
// Assuming your 'root' logger is configured correctlyleo;process;