Merge pull request #361 from CartoDB/logs-conf

Allow to use absolute paths for log files
This commit is contained in:
Raul Ochoa 2016-09-14 20:16:09 +02:00 committed by GitHub
commit 97ac1b8db6
2 changed files with 16 additions and 15 deletions

View File

@ -1,6 +1,9 @@
1.35.0 - 2016-mm-dd 1.35.0 - 2016-mm-dd
------------------- -------------------
Bug fixes:
* Allow to use absolute paths for log files.
Announcements: Announcements:
* Removes support for optional rollbar logging. * Removes support for optional rollbar logging.

24
app.js
View File

@ -37,30 +37,28 @@ env.api_hostname = require('os').hostname().split('.')[0];
_.extend(global.settings, env); _.extend(global.settings, env);
global.log4js = require('log4js'); global.log4js = require('log4js');
var log4js_config = { var log4jsConfig = {
appenders: [], appenders: [],
replaceConsole: true replaceConsole: true
}; };
if ( env.log_filename ) { if ( env.log_filename ) {
var logdir = path.dirname(env.log_filename); var logFilename = path.resolve(env.log_filename);
// See cwd inlog4js.configure call below var logDirectory = path.dirname(logFilename);
logdir = path.resolve(__dirname, logdir); if (!fs.existsSync(logDirectory)) {
if ( ! fs.existsSync(logdir) ) { console.error("Log filename directory does not exist: " + logDirectory);
console.error("Log filename directory does not exist: " + logdir);
process.exit(1); process.exit(1);
} }
console.log("Logs will be written to " + env.log_filename); console.log("Logs will be written to " + logFilename);
log4js_config.appenders.push( log4jsConfig.appenders.push(
{ type: "file", filename: env.log_filename } { type: "file", absolute: true, filename: logFilename }
); );
} else { } else {
log4js_config.appenders.push( log4jsConfig.appenders.push(
{ type: "console", layout: { type:'basic' } } { type: "console", layout: { type:'basic' } }
); );
} }
global.log4js.configure(log4jsConfig);
global.log4js.configure(log4js_config, { cwd: __dirname });
global.logger = global.log4js.getLogger(); global.logger = global.log4js.getLogger();
@ -85,7 +83,7 @@ process.on('uncaughtException', function(err) {
process.on('SIGHUP', function() { process.on('SIGHUP', function() {
global.log4js.clearAndShutdownAppenders(function() { global.log4js.clearAndShutdownAppenders(function() {
global.log4js.configure(log4js_config); global.log4js.configure(log4jsConfig);
global.logger = global.log4js.getLogger(); global.logger = global.log4js.getLogger();
console.log('Log files reloaded'); console.log('Log files reloaded');
}); });