mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
feature: adding the option to provide appender instance in config
This commit is contained in:
parent
8221adac2d
commit
efd5d2c3f4
@ -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),
|
||||
|
||||
@ -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: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user