From 8b9c0a6e857a5d56f05cee68a65e122db010f08d Mon Sep 17 00:00:00 2001 From: Jari Bakken Date: Tue, 10 Mar 2015 16:30:56 +0100 Subject: [PATCH] Reduce logging in production. --- app.js | 6 +++++- lib/logger.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 73b9528d9e..7523d8344c 100644 --- a/app.js +++ b/app.js @@ -33,7 +33,11 @@ app.use(validator([])); app.set('trust proxy'); app.locals.baseUriPath = baseUriPath; -app.use(log4js.connectLogger(logger, {format: ':remote-addr :status :method :url :response-timems'})); +app.use(log4js.connectLogger(logger, { + format: ':remote-addr :status :method :url :response-timems', + level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR +})); + app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242); app.use(baseUriPath, express.static(__dirname + '/public')); diff --git a/lib/logger.js b/lib/logger.js index 60b8a2bece..713ad2c3a5 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -3,4 +3,13 @@ var log4js = require('log4js'); log4js.clearAppenders(); log4js.addAppender(log4js.appenders.console()); -module.exports = log4js.getLogger('unleash'); \ No newline at end of file +var logger = log4js.getLogger('unleash'); + +// TODO: make level configurable +if (process.env.NODE_ENV === 'production') { + logger.setLevel(log4js.levels.ERROR); +} else { + logger.setLevel(log4js.levels.DEBUG); +} + +module.exports = logger; \ No newline at end of file