One stop logging utility.
npm install --save papel
import papel from 'papel';
papel.log('msg');
// info msg
papel.error('just', 'like', 'console');
// error just like console
papel.warn('hi')
// warn hi
Priority | Method |
---|---|
0 | .error |
1 | .warn |
2 | .debug , .log |
3 | .info |
4 | .verbose |
5 | .silly |
You can filter logs by setting the DEBUG_PRIORITY
environment variable. Only logs of same and lower priority will be logged.
DEBUG_PRIORITY=3 node index.js
By default, Papel logs to console
, but you can add scribes to save to disk or post to a logging service.
If you are performing an asynchronous operation, it is recommended to return a promise so Papel knows when the scribe is done.
It is the scribe's responsibility to respect the DEBUG_PRIORITY
level, therefore you can have different scribes log different priorities.
The scribe is provided with two arguments:
data
contains information about the specific invocationpapelInstance
contains information about the papel instance
papel.addScribe(function(data, papelInstance) {
return new Promise(function (resolve, reject) {
var logs = data.logs;
var priority = data.priority;
var datetime = data.datetime;
var type = data.type;
setTimeout(function() {
resolve();
}, 0);
});
});
When adding a scribe, a callback to remove it is returned.
var removeScribe = papel.addScribe(function() {});
removeScribe();
You can create new Papel instances like debug.
import { Papel } from 'papel';
var dbPapel = new Papel({ name: 'db' });
dbPapel.error('boom');
// db:error boom
The new instance defaults to the same scribes and methods, but you can customize these through the options.
new Papel(options);
Instance name. Shows in the console and is provided to scribes.
This option defaults to the same scribes as the default instance. Note that if you do not provide this option, adding/removing scribes will affect both instances.
Determines which priority should be logged. Defaults to DEBUG_PRIORITY
.
You can filter instances by setting the DEBUG
environment variable. Glob patterns supported by minimatch are allowed.
DEBUG=db node index.js
Copyright (c) 2015 Marius Craciunoiu. Licensed under the MIT license.