Add optional timezoneOffset config for appenders

Example:
    log4js.configure({
        appenders: [{type: 'console', timezoneOffset: -540}],
        replaceConsole: true
    });

The expected value is the equivalent of (new Date).getTimezoneOffset()
In this example, -540 is the value for JST.
This allows machines members of world-wide-spread cluster to all report
log time-stamps using the same timezone (or adapt the timezone to a
local different from the system)
This commit is contained in:
Quentin Brandon
2015-03-20 11:51:23 +09:00
parent 4a217afc37
commit af69eddd1c
7 changed files with 44 additions and 33 deletions

View File

@@ -2,10 +2,10 @@
var layouts = require('../layouts')
, consoleLog = console.log.bind(console);
function consoleAppender (layout) {
function consoleAppender (layout, timezoneOffset) {
layout = layout || layouts.colouredLayout;
return function(loggingEvent) {
consoleLog(layout(loggingEvent));
consoleLog(layout(loggingEvent, timezoneOffset));
};
}
@@ -14,7 +14,7 @@ function configure(config) {
if (config.layout) {
layout = layouts.layout(config.layout.type, config.layout);
}
return consoleAppender(layout);
return consoleAppender(layout, config.timezoneOffset);
}
exports.appender = consoleAppender;