File tree 2 files changed +22
-2
lines changed 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,21 @@ function redisAppender(config, layout) {
15
15
}
16
16
} ) ;
17
17
18
- return function ( loggingEvent ) {
18
+ const appender = function ( loggingEvent ) {
19
19
const message = layout ( loggingEvent ) ;
20
20
redisClient . publish ( config . channel , message , ( err ) => {
21
21
if ( err ) {
22
22
console . error ( `log4js.redisAppender - ${ host } :${ port } Error: ${ util . inspect ( err ) } ` ) ;
23
23
}
24
24
} ) ;
25
25
} ;
26
+
27
+ appender . shutdown = ( cb ) => {
28
+ redisClient . quit ( ) ;
29
+ if ( cb ) cb ( ) ;
30
+ } ;
31
+
32
+ return appender ;
26
33
}
27
34
28
35
function configure ( config , layouts ) {
Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ function setupLogging(category, options) {
19
19
publish : function ( channel , message , callback ) {
20
20
fakeRedis . msgs . push ( { channel : channel , message : message } ) ;
21
21
fakeRedis . publishCb = callback ;
22
- }
22
+ } ,
23
+ quit : function ( ) {
24
+ fakeRedis . quitCalled = true ;
25
+ } ,
23
26
} ;
24
27
}
25
28
} ;
@@ -46,6 +49,7 @@ function setupLogging(category, options) {
46
49
47
50
return {
48
51
logger : log4js . getLogger ( category ) ,
52
+ log4js : log4js ,
49
53
fakeRedis : fakeRedis ,
50
54
fakeConsole : fakeConsole
51
55
} ;
@@ -129,5 +133,14 @@ test('log4js redisAppender', (batch) => {
129
133
t . end ( ) ;
130
134
} ) ;
131
135
136
+ batch . test ( 'shutdown' , ( t ) => {
137
+ const setup = setupLogging ( 'shutdown' , { type : 'redis' , channel : 'testing' } ) ;
138
+
139
+ setup . log4js . shutdown ( ( ) => {
140
+ t . ok ( setup . fakeRedis . quitCalled ) ;
141
+ t . end ( ) ;
142
+ } ) ;
143
+ } ) ;
144
+
132
145
batch . end ( ) ;
133
146
} ) ;
You can’t perform that action at this time.
0 commit comments