Moved abspath option checking into file appender, log4js options now passed to appenders
This commit is contained in:
@@ -50,11 +50,16 @@ function fileAppender (file, layout, logSize, numBackups) {
|
||||
};
|
||||
}
|
||||
|
||||
function configure(config) {
|
||||
function configure(config, options) {
|
||||
var layout;
|
||||
if (config.layout) {
|
||||
layout = layouts.layout(config.layout.type, config.layout);
|
||||
}
|
||||
|
||||
if (options && options.cwd && !config.absolute) {
|
||||
config.filename = path.join(options.cwd, config.filename);
|
||||
}
|
||||
|
||||
return fileAppender(config.filename, layout, config.maxLogSize, config.backups);
|
||||
}
|
||||
|
||||
|
||||
@@ -138,14 +138,14 @@ function clearAppenders () {
|
||||
}
|
||||
}
|
||||
|
||||
function configureAppenders(appenderList) {
|
||||
function configureAppenders(appenderList, options) {
|
||||
clearAppenders();
|
||||
if (appenderList) {
|
||||
appenderList.forEach(function(appenderConfig) {
|
||||
loadAppender(appenderConfig.type);
|
||||
var appender;
|
||||
appenderConfig.makers = appenderMakers;
|
||||
appender = appenderMakers[appenderConfig.type](appenderConfig);
|
||||
appender = appenderMakers[appenderConfig.type](appenderConfig, options);
|
||||
if (appender) {
|
||||
addAppender(appender, appenderConfig.category);
|
||||
} else {
|
||||
@@ -259,10 +259,10 @@ function loadConfigurationFile(filename) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function configureOnceOff(config) {
|
||||
function configureOnceOff(config, options) {
|
||||
if (config) {
|
||||
try {
|
||||
configureAppenders(config.appenders);
|
||||
configureAppenders(config.appenders, options);
|
||||
configureLevels(config.levels);
|
||||
|
||||
if (config.replaceConsole) {
|
||||
@@ -321,25 +321,7 @@ function configure(configurationFileOrObject, options) {
|
||||
getLogger('log4js').warn('Ignoring configuration reload parameter for "object" configuration.');
|
||||
}
|
||||
}
|
||||
|
||||
if (options.hasOwnProperty('cwd')) {
|
||||
if (config.hasOwnProperty('appenders')) {
|
||||
config.appenders.forEach(function(appender) {
|
||||
if (!appender.hasOwnProperty('type')) return;
|
||||
|
||||
if (appender.type === 'file') {
|
||||
if(!appender.hasOwnProperty('filename')) return;
|
||||
if(appender.hasOwnProperty('absolute')) {
|
||||
if(appender.absolute) return;
|
||||
}
|
||||
|
||||
appender.filename = path.join(options.cwd, appender.filename);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
configureOnceOff(config);
|
||||
configureOnceOff(config, options);
|
||||
}
|
||||
|
||||
var originalConsoleFunctions = {
|
||||
|
||||
Reference in New Issue
Block a user