diff --git a/NEWS.md b/NEWS.md index f2b9644f..e199dbaf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,8 @@ New features: - - Reload log files on SIGUSR2 + - Add support for log_filename directive + - Reopen log file on SIGHUP, for better logrotate integration 1.10.1 -- 2014-03-21 ------------------- diff --git a/app.js b/app.js index 48de17a3..dd9082ab 100755 --- a/app.js +++ b/app.js @@ -31,12 +31,21 @@ _.extend(global.settings, global.environment); global.log4js = require('log4js') log4js_config = { - appenders: [ - { type: "console", layout: { type:'basic' } } - ], + appenders: [], replaceConsole:true }; +if ( global.environment.log_filename ) { + console.log("Logs will be written to " + global.environment.log_filename); + log4js_config.appenders.push( + { type: "file", filename: global.environment.log_filename } + ); +} else { + log4js_config.appenders.push( + { type: "console", layout: { type:'basic' } } + ); +} + if ( global.environment.rollbar ) { log4js_config.appenders.push({ type: __dirname + "/lib/cartodb/log4js_rollbar.js", @@ -78,6 +87,9 @@ process.on('SIGUSR1', function() { process.on('SIGUSR2', function() { ws.dumpCacheStats(); +}); + +process.on('SIGHUP', function() { log4js.configure(log4js_config); console.log('Log files reloaded'); }); diff --git a/config/environments/development.js.example b/config/environments/development.js.example index 41eb4a17..aaa5f51b 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -36,6 +36,10 @@ var config = { ,enable_cors: true ,cache_enabled: false ,log_format: ':req[X-Real-IP] :method :req[Host]:url :status :response-time ms -> :res[Content-Type] (:res[X-Tiler-Profiler])' + // If log_filename is given logs will be written + // there, in append mode. Otherwise stdout is used (default). + // Log file will be re-opened on receiving the HUP signal + ,log_filename: 'logs/node-windshaft.log' // Templated database username for authorized user // Supported labels: 'user_id' (read from redis) ,postgres_auth_user: 'development_cartodb_user_<%= user_id %>' diff --git a/config/environments/production.js.example b/config/environments/production.js.example index bc50d114..345f8c8f 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -36,6 +36,10 @@ var config = { ,enable_cors: true ,cache_enabled: true ,log_format: ':req[X-Real-IP] :method :req[Host]:url :status :response-time ms -> :res[Content-Type] (:res[X-Tiler-Profiler])' + // If log_filename is given logs will be written + // there, in append mode. Otherwise stdout is used (default). + // Log file will be re-opened on receiving the HUP signal + ,log_filename: 'logs/node-windshaft.log' // Templated database username for authorized user // Supported labels: 'user_id' (read from redis) ,postgres_auth_user: 'cartodb_user_<%= user_id %>' diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index 4302c99d..be849b14 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -36,6 +36,10 @@ var config = { ,enable_cors: true ,cache_enabled: true ,log_format: ':req[X-Real-IP] :method :req[Host]:url :status :response-time ms (:res[X-Tiler-Profiler]) -> :res[Content-Type]' + // If log_filename is given logs will be written + // there, in append mode. Otherwise stdout is used (default). + // Log file will be re-opened on receiving the HUP signal + ,log_filename: 'logs/node-windshaft.log' // Templated database username for authorized user // Supported labels: 'user_id' (read from redis) ,postgres_auth_user: 'cartodb_staging_user_<%= user_id %>' diff --git a/config/environments/test.js.example b/config/environments/test.js.example index 8ded2588..a89d83cd 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -36,6 +36,10 @@ var config = { ,enable_cors: true ,cache_enabled: false ,log_format: '[:date] :req[X-Real-IP] :method :req[Host]:url :status :response-time ms -> :res[Content-Type] (:res[X-Tiler-Profiler])' + // If log_filename is given logs will be written + // there, in append mode. Otherwise stdout is used (default). + // Log file will be re-opened on receiving the HUP signal + //,log_filename: 'logs/node-windshaft.log' // Templated database username for authorized user // Supported labels: 'user_id' (read from redis) ,postgres_auth_user: 'test_windshaft_cartodb_user_<%= user_id %>'