mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-22 03:34:14 +00:00
chore(logging): add Newrelic and Email transports for Winston
This will send an email on errors logged with winston and thus removes the old error emailing code.
This commit is contained in:
parent
ae847facda
commit
71f4371d9c
5 changed files with 29 additions and 15 deletions
|
|
@ -11,6 +11,9 @@
|
|||
"SMTP_USER":"user@domain.com",
|
||||
"SMTP_PASS":"password",
|
||||
"SMTP_SERVICE":"Gmail",
|
||||
"SMTP_HOST":"smtp.gmail.com",
|
||||
"SMTP_PORT": 587,
|
||||
"SMTP_TLS": true,
|
||||
"STRIPE_API_KEY":"aaaabbbbccccddddeeeeffff00001111",
|
||||
"STRIPE_PUB_KEY":"22223333444455556666777788889999",
|
||||
"PAYPAL_MERCHANT":"paypal-merchant@gmail.com",
|
||||
|
|
|
|||
|
|
@ -46,7 +46,9 @@
|
|||
"passport-facebook": "~1.0.2",
|
||||
"newrelic": "~1.3.0",
|
||||
"connect-ratelimit": "0.0.6",
|
||||
"winston": "~0.7.2"
|
||||
"winston": "~0.7.2",
|
||||
"winston-mail": "~0.2.7",
|
||||
"winston-newrelic": "~0.1.4"
|
||||
},
|
||||
"private": true,
|
||||
"subdomain": "habitrpg",
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
var nconf = require('nconf');
|
||||
var winston = require('winston');
|
||||
require('winston-mail').Mail;
|
||||
require('winston-newrelic');
|
||||
|
||||
var logger;
|
||||
|
||||
if (logger == null) {
|
||||
// We currently don't support logging on Heroku
|
||||
if (nconf.get('NODE_ENV') != 'production') {
|
||||
logger = new (winston.Logger)({
|
||||
transports: [
|
||||
new (winston.transports.Console)({colorize: true}),
|
||||
|
|
@ -12,6 +13,19 @@ if (logger == null) {
|
|||
// TODO: Add email, loggly, or mongodb transports
|
||||
]
|
||||
});
|
||||
if (nconf.get('NODE_ENV') == 'production') {
|
||||
logger.add(winston.transport.newrelic, {});
|
||||
logger.add(winston.transports.Mail, {
|
||||
to: nconf.get('ADMIN_EMAIL') || nconf.get('SMTP_USER'),
|
||||
from: "HabitRPG <" + nconf.get('SMTP_USER') + ">",
|
||||
subject: "HabitRPG Error",
|
||||
host: nconf.get('SMTP_HOST'),
|
||||
port: nconf.get('SMTP_PORT'),
|
||||
tls: nconf.get('SMTP_TLS'),
|
||||
username: nconf.get('SMTP_USER'),
|
||||
password: nconf.get('SMTP_PASS'),
|
||||
level: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ var cluster = require("cluster");
|
|||
var _ = require('lodash');
|
||||
var nconf = require('nconf');
|
||||
var utils = require('./utils');
|
||||
var logging = require('./logging');
|
||||
utils.setupConfig();
|
||||
|
||||
var logging = require('./logging');
|
||||
var isProd = nconf.get('NODE_ENV') === 'production';
|
||||
var isDev = nconf.get('NODE_ENV') === 'development';
|
||||
|
||||
|
|
|
|||
16
src/utils.js
16
src/utils.js
|
|
@ -2,17 +2,17 @@ var nodemailer = require('nodemailer');
|
|||
var nconf = require('nconf');
|
||||
var crypto = require('crypto');
|
||||
var path = require("path");
|
||||
var logging = require('./logging');
|
||||
|
||||
module.exports.sendEmail = function(mailData) {
|
||||
var smtpTransport = nodemailer.createTransport("SMTP",{
|
||||
service: nconf.get('SMTP_SERVICE'),
|
||||
service: nconf.get('SMTP_SERVICE'),
|
||||
auth: {
|
||||
user: nconf.get('SMTP_USER'),
|
||||
pass: nconf.get('SMTP_PASS')
|
||||
user: nconf.get('SMTP_USER'),
|
||||
pass: nconf.get('SMTP_PASS')
|
||||
}
|
||||
});
|
||||
smtpTransport.sendMail(mailData, function(error, response){
|
||||
var logging = require('./logging');
|
||||
if(error) logging.error(error);
|
||||
else logging.info("Message sent: " + response.message);
|
||||
smtpTransport.close(); // shut down the connection pool, no more messages
|
||||
|
|
@ -49,6 +49,7 @@ module.exports.setupConfig = function(){
|
|||
// // * https://developers.google.com/chrome-developer-tools/docs/heap-profiling
|
||||
// // * https://developers.google.com/chrome-developer-tools/docs/memory-analysis-101
|
||||
// agent = require('webkit-devtools-agent');
|
||||
// var logging = require('./logging');
|
||||
// logging.info("To debug memory leaks:" +
|
||||
// "\n\t(1) Run `kill -SIGUSR2 " + process.pid + "`" +
|
||||
// "\n\t(2) open http://c4milo.github.com/node-webkit-agent/21.0.1180.57/inspector.html?host=localhost:1337&page=0");
|
||||
|
|
@ -70,12 +71,7 @@ module.exports.errorHandler = function(err, req, res, next) {
|
|||
"\n\nheaders: " + JSON.stringify(req.headers) +
|
||||
"\n\nbody: " + JSON.stringify(req.body) +
|
||||
(res.locals.ops ? "\n\ncompleted ops: " + JSON.stringify(res.locals.ops) : "");
|
||||
module.exports.sendEmail({
|
||||
from: "HabitRPG <" + nconf.get('SMTP_USER') + ">",
|
||||
to: nconf.get('ADMIN_EMAIL') || nconf.get('SMTP_USER'),
|
||||
subject: "HabitRPG Error",
|
||||
text: stack
|
||||
});
|
||||
var logging = require('./logging');
|
||||
logging.error(stack);
|
||||
var message = err.message ? err.message : err;
|
||||
message = (message.length < 200) ? message : message.substring(0,100) + message.substring(message.length-100,message.length);
|
||||
|
|
|
|||
Loading…
Reference in a new issue