chillogger
A logger Util that:
- Is colorful
- Can trace where in the code log was written
- Extendable transport
- Extendable levels dictionary
Getting Started
npm install -s chillogger
//import chilloggerconst Chillogger = ;//create an instanceconst logger = //Usage option 1: using logger.log:// logger.log("level", message, ...metaObjects)logger
API
chilloger is configurable on 2 levels:
- instance: Set the config on the chilloger instance
- global: Set the defaults for any instance constructed from now on
Instance is created with:
new Logger([name][,options])
name
{string|Boolen} add logger name; in the build in node-console transport this will be included in any line logged using the instance iftrue
is passed, chillogger will generate an id for youoptions
{Object}transport
: {function[]} an array of functions that handles new log message, called by the instance withf(logMessage, loggerInstance)
Default:built in node-console transport
levels
: {Object} An object mapping log labels (for example "trace") to level (4) Default: seebaseLevels
.level
: {number} Max level to log Default:3
trace
: {boolean} Shows error stack trace, and enables time, and timeEnd, and chillogger's ability to trace log to file/line, Default:false
.verbosity
: {number} built in console trasnport verbosity use0
,1
, or1
Default:0
- Returns: loggerInstance
Some of these options are also configurable globally:
// set default traceprocessenvtrace = 0// orLogger // set default levelprocessenvlevel = 4 // orLogger // set defaul verbosityprocessenvverbosity = 2 //orLogger
chillogger instance
public methods
setLevel(level)
setTrace(trace)
setVerbosity(verbosity)
log(level, messageString, ...meta)
error(error)
time(label)
: time tracker that tells you where (file and line) timer startedtimeEnd(label)
Also, all names of levels passed to the instance constructor as options, plus the build in levels are exposed using
log;
so if you have a level named "tellMommy" you can go
logger`
Keep in mind that if your level name is reserved for chilloggers methods, it will not replace it.
baseLevels
The default levels map
fatal: 0 alert: 0 error: 1 warn: 2 info: 3 debug: 4 todo: 4 deprecated: 4 time: 5 trace: 5
log message object
name // logger instance name message //string message meta //an array of metadata objects; level //log level levelLabel //log level label ts: Date src: //src will be included only in case the instance is running with trace===true file //file name line //line in code that called chillogger }