From d4d63af2b006967a6b5845c2a88c014005c46e0a Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Sat, 3 Dec 2016 14:09:09 +0100 Subject: [PATCH] Option to disable request logging. Because all request details are available via prometheus there is no need to also log all requests. This solves #164 but we should still replace log4j with something else. --- lib/app.js | 11 +++++++---- lib/options.js | 5 ++++- lib/server-impl.js | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/app.js b/lib/app.js index 4b98379f15..5a414b6797 100644 --- a/lib/app.js +++ b/lib/app.js @@ -41,10 +41,13 @@ module.exports = function (config) { } app.use(bodyParser.json({ strict: false })); - app.use(log4js.connectLogger(logger, { - format: ':status :method :url :response-timems', - level: 'auto', // 3XX=WARN, 4xx/5xx=ERROR - })); + + if(config.enableRequestLogger) { + app.use(log4js.connectLogger(logger, { + format: ':status :method :url :response-timems', + level: 'auto', // 3XX=WARN, 4xx/5xx=ERROR + })); + } // Setup API routes const apiRouter = express.Router(); // eslint-disable-line new-cap diff --git a/lib/options.js b/lib/options.js index 92074bf998..99cc8f84db 100644 --- a/lib/options.js +++ b/lib/options.js @@ -1,12 +1,15 @@ 'use strict'; const { publicFolder } = require('unleash-frontend'); +const isDev = () => process.env.NODE_ENV === 'development'; + const DEFAULT_OPTIONS = { databaseUrl: process.env.DATABASE_URL, port: process.env.HTTP_PORT || process.env.PORT || 4242, baseUriPath: process.env.BASE_URI_PATH || '', serverMetrics: true, publicFolder, + enableRequestLogger: isDev() ? true : false }; module.exports = { @@ -14,7 +17,7 @@ module.exports = { const options = Object.assign({}, DEFAULT_OPTIONS, opts); // If we are running in development we should assume local db - if(process.env.NODE_ENV === 'development' && !options.databaseUrl) { + if(isDev() && !options.databaseUrl) { options.databaseUrl = 'postgres://unleash_user:passord@localhost:5432/unleash'; } diff --git a/lib/server-impl.js b/lib/server-impl.js index 1de7ddc66f..e36a2257a6 100644 --- a/lib/server-impl.js +++ b/lib/server-impl.js @@ -19,6 +19,7 @@ function createApp (options) { const config = { baseUriPath: options.baseUriPath, serverMetrics: options.serverMetrics, + enableRequestLogger: options.enableRequestLogger, port: options.port, publicFolder: options.publicFolder, stores,