diff --git a/app.js b/app.js index 480cf0a7c..720dc5094 100644 --- a/app.js +++ b/app.js @@ -24,7 +24,9 @@ var app = express(), }), NODE_ENV = env.get("NODE_ENV"), WWW_ROOT = path.resolve(__dirname, "public"), - server; + server, + messina, + logger; nunjucksEnv.addFilter("instantiate", function (input) { var tmpl = new nunjucks.Template(input); @@ -82,40 +84,20 @@ var routes = require("./routes"); nunjucksEnv.express(app); app.disable("x-powered-by"); -app.use(express.logger(NODE_ENV === "development" ? "dev" : "")); +if (env.get("ENABLE_GELF_LOGS")) { + messina = require("messina"); + logger = messina("webmaker.org-" + env.get("NODE_ENV") || "development"); + logger.init(); + app.use(logger.middleware()); +} else { + app.use(express.logger()); +} + if ( !! env.get("FORCE_SSL")) { app.use(helmet.hsts()); app.enable("trust proxy"); } -/** - * Crash isolation and error handling, logging - */ -if (env.get("GRAYLOG_HOST")) { - GLOBAL.graylogHost = env.get("GRAYLOG_HOST"); - GLOBAL.graylogFacility = env.get("GRAYLOG_FACILITY"); - require("graylog"); -} - -function reportError(error, isFatal) { - try { - var severity = isFatal ? "CRASH" : "ERROR"; - console.error(severity + ": " + error.stack); - if (!GLOBAL.graylogHost) { - return; - } - log("[" + severity + "] webmaker.org failure.", - error.message, { - level: isFatal ? LOG_CRIT : LOG_ERR, - stack: error.stack, - _fullStack: error.stack - } - ); - } catch (err) { - console.error("Internal Error: unable to report error to graylog, err=" + err); - } -} - app.use(function (req, res, next) { var guard = domain.create(); guard.add(req); @@ -140,8 +122,8 @@ app.use(function (req, res, next) { // But don't keep the process open just for that! killtimer.unref(); - // Try and report this crash to graylog - reportError(err, true); + // report this crash + console.error(err); // Try and shutdown the server, cluster worker isolate(function () { @@ -166,7 +148,7 @@ app.use(function (req, res, next) { guard.dispose(); } catch (err2) { - console.error('Internal error shutting down domain: ', err2.stack); + logger.error('Internal error shutting down domain: ', err2.stack); } process.exit(1); @@ -254,7 +236,7 @@ app.use(function (req, res, next) { // Final error-handling middleware app.use(function (err, req, res, next) { err.status = err.status || 500; - reportError(err); + console.error(err); res.status(err.status); res.render('error.html', { message: err.message, diff --git a/env.dist b/env.dist index bde9f0f49..2fed5d3f1 100644 --- a/env.dist +++ b/env.dist @@ -78,8 +78,8 @@ export AWS_SECRET_KEY="irrelephent" # Disable sending the event creation email by default until we're allowed to export ALLOW_SEND_EVENT_CREATE_EMAIL=false -# GRAYLOG (optional, leave blank if not using Graylog) -export GRAYLOG_HOST="hostname-for-graylog-server" +# Set to true to enable GELF formatted logging. setting to false will enable express.logger for logging. +export ENABLE_GELF_LOGS=false # What domains to enable SSO on. Space-delimited export SSO_DOMAINS="http://localhost:3000 http://localhost:3500 http://localhost:5000 http://localhost:7777 http://localhost:8888 http://localhost:12416" diff --git a/package.json b/package.json index 3d47cfae8..c2eabc4ac 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "commander": "2.0.x", "csv": "0.3.x", "express": "3.2.0", - "graylog": "0.1.3", "habitat": "0.4.1", "helmet": "0.0.11", "knox": "0.8.x", @@ -25,6 +24,7 @@ "makeapi-client": "https://github.com/mozilla/makeapi-client/tarball/v0.5.11", "mapquest": "0.0.1", "markdown": "0.4.x", + "messina": "0.1.1", "moment": "2.2.1", "mox-server": "https://github.com/Pomax/mox-server/archive/master.tar.gz", "mysql": "2.0.x",