logger with multiple stores and auto context support
Features
- normal debug/info/warn/error operation
- support time/timeEnd for profiling
- multiple stores(console/file/db...)
- auto flush on process exit(SIGINT)
- log the context(through the web request...)
Usage
when you create a new logger object, you can set the following options:
stores
: store's map object. the key is the store instance's name. Each store has the common options:class
: the store class, which can be the package name string, or the require returnlevel
: the threshold level(DEBUG/INFO/WARN/ERROR/OFF
). default isDEBUG
time
: whether to record time/timeEnd operation. default istrue
context
: the context variable names. these variables are attached in theprocess.domain
if you do not set the stores
option, a internal ConsoleStore
will be used. it can also be retreived by require('ctx-logger').ConsoleStore
.
var Logger = ; //use the internal ConsoleStorevar logger = ;... //create a logger with a console store and a file storevar logger = stores: console: class: LoggerConsoleStore file: class: 'ctx-logger-file-store' dir: './log';... logger;logger;logger;logger;logger;logger;
Used with context
In web http request, you may want to distinguish the differenct log messages produced by differenct users with the only one logger. Here, you can! see the code(with express
):
//add the domain middlewareapp; var logger = stores: console: class: LoggerConsoleStore context: 'userId'; app;
the output will be:
2015-09-15 11:11:11 DEBUG [kiliwalk] visit test page
Stores
Internal console store
you can choose whether enable colored output in console. just set the color
option. default is true
.
var logger = stores: console: class: LoggerConsoleStore color: false;
License :
Licensed under MIT
Copyright (c) 2015 kiliwalk