Add optional support for rollbar

Closes #150
Logs messages of severity ERROR or higher
This commit is contained in:
Sandro Santilli 2014-03-13 12:09:39 +01:00
parent 1f3aca837b
commit 65f31fd7c1
7 changed files with 92 additions and 1 deletions

View File

@ -1,6 +1,10 @@
1.9.0 - 2014-MM-DD
------------------
New features:
- Add optional support for rollbar (#137)
Enhancements:
* Allow configuring log_format (#131)

13
app.js
View File

@ -31,7 +31,16 @@ log4js_config = {
],
replaceConsole:true
};
if ( global.settings.rollbar ) {
log4js_config.appenders.push({
type: __dirname + "/app/models/log4js_rollbar.js",
options: global.settings.rollbar
});
}
log4js.configure(log4js_config);
global.logger = log4js.getLogger();
// kick off controller
@ -42,3 +51,7 @@ app.listen(global.settings.node_port, global.settings.node_host, function() {
global.settings.node_host + ":" + global.settings.node_port +
" with base_url " + global.settings.base_url);
});
process.on('uncaughtException', function(err) {
logger.error('Uncaught exception: ' + err.stack);
});

View File

@ -0,0 +1,49 @@
var rollbar = require("rollbar");
/**
* Rollbar Appender. Sends logging events to Rollbar using node-rollbar
*
* @param config object with rollbar configuration data
* {
* token: 'your-secret-token',
* options: node-rollbar options
* }
*/
function rollbarAppender(config) {
var opt = config.options;
rollbar.init(opt.token, opt.options);
return function(loggingEvent) {
/*
For logger.trace('one','two','three'):
{ startTime: Wed Mar 12 2014 16:27:40 GMT+0100 (CET),
categoryName: '[default]',
data: [ 'one', 'two', 'three' ],
level: { level: 5000, levelStr: 'TRACE' },
logger: { category: '[default]', _events: { log: [Object] } } }
*/
// Levels:
// TRACE 5000
// DEBUG 10000
// INFO 20000
// WARN 30000
// ERROR 40000
// FATAL 50000
//
// We only log error and higher errors
//
if ( loggingEvent.level.level < 40000 ) return;
rollbar.reportMessage(loggingEvent.data);
};
}
function configure(config) {
return rollbarAppender(config);
}
exports.name = "rollbar";
exports.appender = rollbarAppender;
exports.configure = configure;

View File

@ -40,3 +40,11 @@ module.exports.tableCacheMax = 8192;
module.exports.tableCacheMaxAge = 1000*60*10;
// Temporary directory, make sure it is writable by server user
module.exports.tmpDir = '/tmp';
// Optional rollbar support
module.exports.rollbar = {
token: 'secret',
// See http://github.com/rollbar/node_rollbar#configuration-reference
options: {
handler: 'inline'
}
}

View File

@ -40,3 +40,11 @@ module.exports.tableCacheMax = 8192;
module.exports.tableCacheMaxAge = 1000*60*10;
// Temporary directory, make sure it is writable by server user
module.exports.tmpDir = '/tmp';
// Optional rollbar support
module.exports.rollbar = {
token: 'secret',
// See http://github.com/rollbar/node_rollbar#configuration-reference
options: {
handler: 'inline'
}
}

8
npm-shrinkwrap.json generated
View File

@ -122,6 +122,14 @@
}
}
},
"rollbar": {
"version": "0.3.1",
"dependencies": {
"node-uuid": {
"version": "1.4.1"
}
}
},
"redis": {
"version": "0.7.1"
},

View File

@ -26,7 +26,8 @@
"oauth-client": "0.2.0",
"node-uuid":"1.3.3",
"lru-cache":"~2.2.2",
"log4js": "~0.6.10"
"log4js": "~0.6.10",
"rollbar": "~0.3.1"
},
"devDependencies": {
"redis": "0.7.1",