feat(loggly): change tag based on base_url, logs internal server errors

This commit is contained in:
Matteo Pagliazzi 2014-12-13 14:48:14 +01:00
parent 9d6caaa138
commit dac2fc682d
3 changed files with 13 additions and 5 deletions

View file

@ -284,14 +284,15 @@ api.cron = function(req, res, next) {
User.findById(user._id, cb);
}
], function(err, saved) {
if(err) logging.loggly({error: e, stack: e.stack})
if(err) logging.loggly({error: "Cron caught", stack: e.stack || e})
res.locals.user = saved;
next(err,saved);
user = progress = quest = null;
});
}catch(e){
logging.loggly({
error: e.stack || e
error: "Cron uncaught",
stack: e.stack || e
});
throw e;
}

View file

@ -3,6 +3,8 @@ var winston = require('winston');
require('winston-mail').Mail;
require('winston-newrelic');
var logger, loggly;
if (nconf.get('NODE_ENV') == 'production'){
var loggly = require('loggly').createClient({
token: nconf.get('LOGGLY:token'),
@ -14,13 +16,11 @@ if (nconf.get('NODE_ENV') == 'production'){
//
// Optional: Tag to send with EVERY log message
//
tags: ['heroku'],
tags: [('heroku-'+nconf.get('BASE_URL'))],
json: true
});
}
var logger;
if (logger == null) {
logger = new (winston.Logger)({});
if (nconf.get('NODE_ENV') == 'production') {

View file

@ -75,6 +75,13 @@ module.exports.errorHandler = function(err, req, res, next) {
"\n\nbody: " + JSON.stringify(req.body) +
(res.locals.ops ? "\n\ncompleted ops: " + JSON.stringify(res.locals.ops) : "");
logging.error(stack);
logging.loggly({
error: "Uncaught error",
stack: (err.stack || err.message || err),
body: req.body, headers: req.header,
auth: (req.headers['x-api-user'] + ' | ' + req.headers['x-api-key']),
originalUrl: req.originalUrl
});
var message = err.message ? err.message : err;
message = (message.length < 200) ? message : message.substring(0,100) + message.substring(message.length-100,message.length);
res.json(500,{err:message}); //res.end(err.message);