unilog-console v0.1.0
unilog-console
A node.js unilog back-end which logs nicely formatted to the console.
2014-03-13 10:51:45.103 | INFO | Starting application…
2014-03-13 10:51:45.105 | DEBUG | Connecting to the database at "mongodb://localhost/test"…
2014-03-13 10:51:45.157 | ERROR | Failed connecting to the database. Will try again soon.Quickstart
unilog-console is automatically used as back-end for unilog by default. You don't have to install or set up anything.
// You can simply configure unilog's default console back-end.
require('unilog').config({
console: { /* console configuration */ }
});
// or manually create a new back-end instance if you need one
var Console = require('unilog-console');
var backend = new Console({ /* optional configuration */ });Filtering the output is simple:
$ export UNILOG='*:info main:trace mongodb:debug'
$ node .Methods
new Console(options)
Creates a new instance and configures it using .config(options).
Implicitly uses the UNILOG environment variable for configuring levels before calling .config(options).
This is similar to .config({ levels: process.env.UNILOG }).
Main path is automatically derived from the require.main module's filename. If the module is contained within a node_modules folder (e.g. when running tests) then its containing folder will be used.
.config({options})
Available options:
derivesGroupIdFromStack'always'- always captures the stack of a log event to derive the group ID from it'supportive'(default on construction) - only capture the stack of a log event if the group ID couldn't be determined otherwisefalse- never capture the stack trace
mainPath- main path of the project which is used as a base path when deriving a source file's group IDstring- directly specify a main path (trailing slashes will be removed)module- the directory path of the module'sfilenamewill be used
levels- log output levelsstring- e.g.'*:info main:trace mongodb:debug'object- e.g.{ '*': 'info', 'main': 'trace', 'mongodb': 'debug' }
resetLevelsfalse(default) -levelswill be merged with previously defined levelstrue- previously set levels will be reset before optionally newlevelsare applied
.putEvent(event)
See unilog's back-end documentation of .putEvent(event).
.eventEnabled(event)
See unilog's back-end documentation of .eventEnabled(event).
Output Destination
trace,debugandinfolog toprocess.stdoutwarn,errorandfatallog toprocess.stderr
Installation
$ npm install unilog-consoleTesting
$ npm install
$ npm testTo-Do
- Support more library module locations, e.g.
.node_modules,.node_librariesand*/lib/nodewhen deriving group IDs. - Add config options to also output an event's
groupId,fileNameandlineNumberwhich is useful for debugging.
License
MIT



