Permalink
Browse files

Add optional support for rollbar

Re-targets to 1.10.0
Also installs an uncaught exception handler

Closes #150
  • Loading branch information...
1 parent 62cbb15 commit 60b552027b03745ac6b7933d08d3a13792e558de Sandro Santilli committed Mar 12, 2014
Showing with 102 additions and 6 deletions.
  1. +6 −1 NEWS.md
  2. +14 −2 app.js
  3. +9 −0 config/environments/production.js.example
  4. +9 −0 config/environments/staging.js.example
  5. +49 −0 lib/cartodb/log4js_rollbar.js
  6. +12 −1 npm-shrinkwrap.json
  7. +3 −2 package.json
View
@@ -1,9 +1,14 @@
-1.9.1 -- 2014-MM-DD
+1.10.0 -- 2014-MM-DD
-------------------
+New features:
+
+ - Add optional support for rollbar (#150)
+
Enhancements:
- Include tiler version in startup log
+ - Install an uncaught exception handler
1.9.0 -- 2014-03-10
-------------------
View
16 app.js
@@ -30,13 +30,22 @@ global.environment = require(__dirname + '/config/environments/' + ENV);
_.extend(global.settings, global.environment);
global.log4js = require('log4js')
-log4js.configure({
+log4js_config = {
appenders: [
{ type: "console", layout: { type:'basic' } }
],
replaceConsole:true
-});
+};
+
+if ( global.environment.rollbar ) {
+ log4js_config.appenders.push({
+ type: __dirname + "/lib/cartodb/log4js_rollbar.js",
+ options: global.environment.rollbar
+ });
+}
+log4js.configure(log4js_config);
+global.logger = log4js.getLogger();
// Include cartodb_windshaft only _after_ the "global" variable is set
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/28
@@ -71,3 +80,6 @@ process.on('SIGUSR2', function() {
ws.dumpCacheStats();
});
+process.on('uncaughtException', function(err) {
+ logger.error('Caught exception: ' + err);
+});
@@ -122,6 +122,15 @@ var config = {
https: 'cartocdn.global.ssl.fastly.net'
}
}
+ // Optional rollbar support
+ ,rollbar: {
+ token: 'secret',
+ // See http://github.com/rollbar/node_rollbar#configuration-reference
+ options: {
+ endpoint: 'https://api.rollbar.com/api/1/',
+ handler: 'inline'
+ }
+ }
};
module.exports = config;
@@ -122,6 +122,15 @@ var config = {
https: 'cartocdn.global.ssl.fastly.net'
}
}
+ // Optional rollbar support
+ ,rollbar: {
+ token: 'secret',
+ // See http://github.com/rollbar/node_rollbar#configuration-reference
+ options: {
+ endpoint: 'https://api.rollbar.com/api/1/',
+ handler: 'inline'
+ }
+ }
};
module.exports = config;
@@ -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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,7 +1,7 @@
{
"private": true,
"name": "windshaft-cartodb",
- "version": "1.9.1",
+ "version": "1.10.0",
"description": "A map tile server for CartoDB",
"keywords": [
"cartodb"
@@ -31,7 +31,8 @@
"redis-mpool": "http://github.com/CartoDB/node-redis-mpool/tarball/0.0.4",
"mapnik": "~0.7.22",
"lzma": "~1.2.3",
- "log4js": "~0.6.10"
+ "log4js": "~0.6.10",
+ "rollbar": "~0.3.1"
},
"devDependencies": {
"mocha": "1.14.0",

0 comments on commit 60b5520

Please sign in to comment.