From 8e9d72982af59e273581135d67b9bf3b444bb4a7 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 7 May 2014 11:03:25 +0200 Subject: [PATCH] Refuse to start if log_filename points to a non-existing directory Closes #189 --- app.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app.js b/app.js index d3836580..4792334d 100755 --- a/app.js +++ b/app.js @@ -7,6 +7,10 @@ * environments: [development, production] */ +var path = require('path'), + fs = require('fs') +; + if ( process.argv[2] ) ENV = process.argv[2]; else if ( process.env['NODE_ENV'] ) ENV = process.env['NODE_ENV']; @@ -33,6 +37,13 @@ log4js_config = { }; if ( global.environment.log_filename ) { + var logdir = path.dirname(global.environment.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); + process.exit(1); + } console.log("Logs will be written to " + global.environment.log_filename); log4js_config.appenders.push( { type: "file", filename: global.environment.log_filename }