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

@@ -20,8 +20,9 @@ process.on('exit', function() {
* @pattern the format that will be added to the end of filename when rolling,
* also used to check when to roll files - defaults to '.yyyy-MM-dd'
* @layout layout function for log messages - defaults to basicLayout
* @timezoneOffset optional timezone offset in minutes - defaults to system local
*/
function appender(filename, pattern, alwaysIncludePattern, layout) {
function appender(filename, pattern, alwaysIncludePattern, layout, timezoneOffset) {
layout = layout || layouts.basicLayout;
var logFile = new streams.DateRollingFileStream(
@@ -32,7 +33,7 @@ function appender(filename, pattern, alwaysIncludePattern, layout) {
openFiles.push(logFile);
return function(logEvent) {
logFile.write(layout(logEvent) + eol, "utf8");
logFile.write(layout(logEvent, timezoneOffset) + eol, "utf8");
};
}
@@ -52,7 +53,7 @@ function configure(config, options) {
config.filename = path.join(options.cwd, config.filename);
}
return appender(config.filename, config.pattern, config.alwaysIncludePattern, layout);
return appender(config.filename, config.pattern, config.alwaysIncludePattern, layout, config.timezoneOffset);
}
function shutdown(cb) {