0.1.0 • Published 9 years ago
err-logger v0.1.0
Error Logger
Logs errors in a JSON format.
Note: This module works as a singleton therefore any configuration will be global.
Install
npm install --save err-logger
Usage
Only logging the error:
var errLog = require('err-logger');
errLog.config({
name: 'Chosen Name'
});
errLog.log( new Error('Very bad thing') );
// Output:
//
// {"name":"Chosen Name","logInfo":true,"hostname":"Air.local","pid":57576,"level":50,"err":{"message":"Very bad thing","name":"Error","stack":"Error: Very bad thing\n at Object.<anonymous> ... "},"msg":"","time":"2015-05-06T15:43:27.658Z","v":0}
Logging extra data:
var errLog = require('err-logger');
errLog.config({
name: 'Chosen Name',
logInfo: true,
serializers: {
data: function(data){
return data.name;
}
}
});
errLog.log(new Error('Very bad thing'), {
data: {
name: 'Admin',
password: 'secret'
}
});
// Output:
//
// {"name":"Chosen Name","logInfo":true,"hostname":"Air.local","pid":57576,"level":50,"data":"Admin","err":{"message":"Very bad thing","name":"Error","stack":"Error: Very bad thing\n at Object.<anonymous> ... "},"msg":"","time":"2015-05-06T15:43:27.667Z","v":0}
Express usage
var errLog = require('err-logger');
errLog.config({
name: 'Chosen Name'
});
app.use(errLog.middleware());
Which is the equivalent to:
app.use(function(err, req, res, next){
errLog.log(err, {
req: req
});
next(err);
});
Options
This module is basically an interface for bunyan, therefore almost all options are transparent.
The only custom option is:
logInfo
: dictates whether the additional gets logged
E.g: If false
, errLog.log(err, {data: "something"})
will not log the {data: "something"}
;
Note: In the additional data the err
key will be overwritten by the error.
Contributing
For any kind of contributions/suggestions please submit and issue or a pull request.
LICENCE
0.1.0
9 years ago