8000 Merge pull request #833 from kaxelson/832-appender-instance · Hacker-FEX/log4js-node@e0abff4 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0abff4

Browse files
authored
Merge pull request log4js-node#833 from kaxelson/832-appender-instance
feature: adding the option to provide appender instance in config
2 parents b46184e + efd5d2c commit e0abff4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/appenders/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ const loadAppenderModule = (type, config) => coreAppenders.get(type)
4242

4343
const createAppender = (name, config) => {
4444
const appenderConfig = config.appenders[name];
45-
const appenderModule = loadAppenderModule(appenderConfig.type, config);
45+
const appenderModule =
46+
appenderConfig.type.configure ? appenderConfig.type : loadAppenderModule(appenderConfig.type, config);
4647
configuration.throwExceptionIf(
4748
config,
4849
configuration.not(appenderModule),

test/tap/configuration-validation-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,26 @@ test('log4js configuration validation', (batch) => {
200200
t.end();
201201
});
202202

203+
batch.test('should use provided appender instance if instance provided', (t) => {
204+
const thing = {};
205+
const cheese = testAppender('cheesy', thing);
206+
const sandboxedLog4js = sandbox.require(
207+
'../../lib/log4js',
208+
{
209+
ignoreMissing: true
210+
}
211+
);
212+
213+
sandboxedLog4js.configure({
214+
appenders: { thing: { type: cheese } },
215+
categories: { default: { appenders: ['thing'], level: 'ERROR' } }
216+
});
217+
218+
t.ok(thing.configureCalled);
219+
t.same(thing.type, cheese);
220+
t.end();
221+
});
222+
203223
batch.test('should not throw error if configure object is freezed', (t) => {
204224
t.doesNotThrow(() => log4js.configure(deepFreeze({
205225
appenders: {

0 commit comments

Comments
 (0)
0