feature: adding the option to provide appender instance in config

This commit is contained in:
Knute Axelson 2019-02-04 11:06:47 -06:00
parent 8221adac2d
commit efd5d2c3f4
2 changed files with 22 additions and 1 deletions

View File

@ -39,7 +39,8 @@ const loadAppenderModule = (type, config) => coreAppenders.get(type) ||
const createAppender = (name, config) => {
const appenderConfig = config.appenders[name];
const appenderModule = loadAppenderModule(appenderConfig.type, config);
const appenderModule =
appenderConfig.type.configure ? appenderConfig.type : loadAppenderModule(appenderConfig.type, config);
configuration.throwExceptionIf(
config,
configuration.not(appenderModule),

View File

@ -226,6 +226,26 @@ test('log4js configuration validation', (batch) => {
t.end();
});
batch.test('should use provided appender instance if instance provided', (t) => {
const thing = {};
const cheese = testAppender('cheesy', thing);
const sandboxedLog4js = sandbox.require(
'../../lib/log4js',
{
ignoreMissing: true
}
);
sandboxedLog4js.configure({
appenders: { thing: { type: cheese } },
categories: { default: { appenders: ['thing'], level: 'ERROR' } }
});
t.ok(thing.configureCalled);
t.same(thing.type, cheese);
t.end();
});
batch.test('should not throw error if configure object is freezed', (t) => {
t.doesNotThrow(() => log4js.configure(deepFreeze({
appenders: {