meta-logger
Lightweight logging library for NodeJS with support of facilities and multiple transports.
Usage
var logger = ; //Setup targetslogger; //Logging without specifying facilitylogger;logger;logger;logger;logger; //Create facility shorthandvar facilityLogger = logger; //Log with facility prefixfacilityLogger;facilityLogger;facilityLogger;facilityLogger;facilityLogger;
Note: console target is set by default.
Configuring logging targets
Console
Prints log messages to stdout (console).
logger;
Method toConsole
overrides previous console target settings. You can use more console targets (for multiple configurations):
logger.to(new Logger.ConsoleTarget({
///... options ...
}));
File
Append log messages to specified file.
Message is formatted same way as to console.
File target can be set for multiple files with different configurations.
logger;
JSON file
Append log messages to specified file in JSON format.
logger;
Log file has following format:
{},
{"timestamp":"2015-06-04T21:20:54.627Z","level":"warn","facility":null,"msg":["Hello %s","warn"]},
{"timestamp":"2015-06-04T21:20:54.629Z","level":"error","facility":"test","msg":["Hello %s","error"]}
...
Custom logging target
Custom target is defined by instance of simple object which implements log
method and registered to logger via to
method.
Following example shows how to define custom target:
var util = ; var { options = options || {}; thisprefix = optionsprefix || ""; }; MyTargetprototype{ console; }; logger;
Following example shows how to inherit BaseTarget:
var { options = options || {}; thisprefix = optionsprefix || ""; loggerBaseTarget; }; util; MyLoggerprototype{ console; };
Custom logging levels
Logging levels can be set by modifying logger.levels
property.
loggerlevels = custom: 4 debug: 3 info: 2 warn: 1 error: 0;
Logger object reference
logger = //Colors library for console coloring colors: //Logging levels levels: debug: 3 info: 2 warn: 1 error: 0 //Object contains registered targets targets: {} //Logging functions , debug: function(args...), info: function(args...), warn: function(args...), error: function(args...), //Facility shorthand facility: function(name){ return , debug: function(args...), info: function(args...), warn: function(args...), error: function(args...) }; //Target shorthands , toConsole: function(options), toFile: function(filename, options), toJsonFile: function(filename, options), //Target constructors BaseTarget: function(options), ConsoleTarget: function(options), FileTarget: function(filename, options), JsonFileTarget: function(filename, options) };
License
This library is published under MIT license.
Copyright (c) 2015 Jiri Hybek, jiri.hybek@cryonix.cz