configure now takes a filename or object
This commit is contained in:
parent
c6dd2398ab
commit
a876dfbe9c
@ -591,14 +591,17 @@ module.exports = function (fileSystem, standardOutput, configPaths) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure (configurationFile) {
|
function configure (configurationFileOrObject) {
|
||||||
if (configurationFile) {
|
var config = configurationFileOrObject;
|
||||||
|
if (typeof(config) === "string") {
|
||||||
|
config = JSON.parse(fs.readFileSync(config, "utf8"));
|
||||||
|
}
|
||||||
|
if (config) {
|
||||||
try {
|
try {
|
||||||
var config = JSON.parse(fs.readFileSync(configurationFile, "utf8"));
|
|
||||||
configureAppenders(config.appenders, fileAppender, consoleAppender);
|
configureAppenders(config.appenders, fileAppender, consoleAppender);
|
||||||
configureLevels(config.levels);
|
configureLevels(config.levels);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("Problem reading log4js config file " + configurationFile + ". Error was \"" + e.message + "\" ("+e.stack+")");
|
throw new Error("Problem reading log4js config " + sys.inspect(config) + ". Error was \"" + e.message + "\" ("+e.stack+")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,24 @@ vows.describe('log4js').addBatch({
|
|||||||
delete messages['tmp-test.log'];
|
delete messages['tmp-test.log'];
|
||||||
log4js.configure('test/with-log-rolling.json');
|
log4js.configure('test/with-log-rolling.json');
|
||||||
assert.equal(messages.watchedFile, 'tmp-test.log');
|
assert.equal(messages.watchedFile, 'tmp-test.log');
|
||||||
|
},
|
||||||
|
'should handle an object or a file name': function(args) {
|
||||||
|
var log4js = args[0],
|
||||||
|
messages = args[1],
|
||||||
|
config = {
|
||||||
|
"appenders": [
|
||||||
|
{
|
||||||
|
"type" : "file",
|
||||||
|
"filename" : "cheesy-wotsits.log",
|
||||||
|
"maxLogSize" : 1024,
|
||||||
|
"backups" : 3,
|
||||||
|
"pollInterval" : 15
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
delete messages['cheesy-wotsits.log'];
|
||||||
|
log4js.configure(config);
|
||||||
|
assert.equal(messages.watchedFile, 'cheesy-wotsits.log');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user