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.; // or manually create a new back-end instance if you need onevar Console = ;var backend = /* 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'sfilename
will be used
-
levels
- log output levelsstring
- e.g.'*:info main:trace mongodb:debug'
object
- e.g.{ '*': 'info', 'main': 'trace', 'mongodb': 'debug' }
-
resetLevels
false
(default) -levels
will be merged with previously defined levelstrue
- previously set levels will be reset before optionally newlevels
are 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
,debug
andinfo
log toprocess.stdout
warn
,error
andfatal
log toprocess.stderr
Installation
$ npm install unilog-console
Testing
$ npm install
$ npm test
To-Do
- Support more library module locations, e.g.
.node_modules
,.node_libraries
and*/lib/node
when deriving group IDs. - Add config options to also output an event's
groupId
,fileName
andlineNumber
which is useful for debugging.
License
MIT