fix for #418 - date formats broken in file appenders

This commit is contained in:
Gareth Jones 2016-11-06 15:47:45 +11:00
parent c951546f59
commit eac6295e4c
5 changed files with 44 additions and 10 deletions

View File

@ -1,3 +1,4 @@
"use strict";
var log4js = require('../lib/log4js');
//log the cheese logger messages to a file, and the console ones as well.
log4js.configure({
@ -55,6 +56,3 @@ anotherLogger.debug("Just checking");
//will also go to console, since that's configured for all categories
var pantsLog = log4js.getLogger('pants');
pantsLog.debug("Something for pants");

View File

@ -1,5 +1,5 @@
//remember to change the require to just 'log4js' if you've npm install'ed it
var log4js = require('./lib/log4js');
var log4js = require('../lib/log4js');
//by default the console appender is loaded
//log4js.loadAppender('console');
//you'd only need to add the console appender if you

36
examples/log-to-files.js Normal file
View File

@ -0,0 +1,36 @@
"use strict";
var path = require('path')
, log4js = require('../lib/log4js');
log4js.configure(
{
appenders: [
{
type: "file",
filename: "important-things.log",
maxLogSize: 10*1024*1024, // = 10Mb
numBackups: 5, // keep five backup files
compress: true, // compress the backups
encoding: 'utf-8',
mode: parseInt('0640', 8),
flags: 'w+'
},
{
type: "dateFile",
filename: "more-important-things.log",
pattern: "yyyy-MM-dd-hh",
compress: true
},
{
type: "stdout"
}
]
}
);
var logger = log4js.getLogger('things');
logger.debug("This little thing went to market");
logger.info("This little thing stayed at home");
logger.error("This little thing had roast beef");
logger.fatal("This little thing had none");
logger.trace("and this little thing went wee, wee, wee, all the way home.");

View File

@ -21,13 +21,13 @@ process.on('exit', function() {
* @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, timezoneOffset) {
function appender(filename, pattern, layout, options, timezoneOffset) {
layout = layout || layouts.basicLayout;
var logFile = new streams.DateRollingFileStream(
filename,
pattern,
{ alwaysIncludePattern: alwaysIncludePattern }
options
);
openFiles.push(logFile);
@ -55,8 +55,8 @@ function configure(config, options) {
return appender(
config.filename,
config.pattern,
config.alwaysIncludePattern,
layout,
config,
config.timezoneOffset
);
}

View File

@ -47,7 +47,7 @@ function fileAppender (file, layout, logSize, numBackups, options, timezoneOffse
//there has to be at least one backup if logSize has been specified
numBackups = numBackups === 0 ? 1 : numBackups;
debug("Creating file appender (", file, ", ", logSize, ", ", numBackups, ", ", options, ")");
debug("Creating file appender (", file, ", ", logSize, ", ", numBackups, ", ", options, ", ", timezoneOffset, ")");
var writer = openTheStream(file, logSize, numBackups, options);
// push file to the stack of open handlers
@ -88,8 +88,8 @@ function configure(config, options) {
layout,
config.maxLogSize,
config.backups,
config.timezoneOffset,
config
config,
config.timezoneOffset
);
}