From e315e77525d34b21b1259d88efa3aef1544af116 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 14 Sep 2016 20:03:05 +0200 Subject: [PATCH] Allow to use absolute paths for log files Fixes #355 --- NEWS.md | 3 +++ app.js | 28 +++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index ea43ca50..f5965a11 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ 1.35.0 - 2016-mm-dd ------------------- +Bug fixes: + * Allow to use absolute paths for log files. + Announcements: * Removes support for optional rollbar logging. diff --git a/app.js b/app.js index 36b76c95..b1d91cb9 100755 --- a/app.js +++ b/app.js @@ -37,30 +37,28 @@ env.api_hostname = require('os').hostname().split('.')[0]; _.extend(global.settings, env); global.log4js = require('log4js'); -var log4js_config = { - appenders: [], - replaceConsole:true +var log4jsConfig = { + appenders: [], + replaceConsole: true }; if ( env.log_filename ) { - var logdir = path.dirname(env.log_filename); - // See cwd inlog4js.configure call below - logdir = path.resolve(__dirname, logdir); - if ( ! fs.existsSync(logdir) ) { - console.error("Log filename directory does not exist: " + logdir); + var logFilename = path.resolve(env.log_filename); + var logDirectory = path.dirname(logFilename); + if (!fs.existsSync(logDirectory)) { + console.error("Log filename directory does not exist: " + logDirectory); process.exit(1); } - console.log("Logs will be written to " + env.log_filename); - log4js_config.appenders.push( - { type: "file", filename: env.log_filename } + console.log("Logs will be written to " + logFilename); + log4jsConfig.appenders.push( + { type: "file", absolute: true, filename: logFilename } ); } else { - log4js_config.appenders.push( + log4jsConfig.appenders.push( { type: "console", layout: { type:'basic' } } ); } - -global.log4js.configure(log4js_config, { cwd: __dirname }); +global.log4js.configure(log4jsConfig); global.logger = global.log4js.getLogger(); @@ -85,7 +83,7 @@ process.on('uncaughtException', function(err) { process.on('SIGHUP', function() { global.log4js.clearAndShutdownAppenders(function() { - global.log4js.configure(log4js_config); + global.log4js.configure(log4jsConfig); global.logger = global.log4js.getLogger(); console.log('Log files reloaded'); });