8000 Shutdown now removes the config reload timer (fix for issue #414) · xcj-coding/log4js-node@3a62714 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a62714

Browse files
author
Gareth Jones
committed
Shutdown now removes the config reload timer (fix for issue log4js-node#414)
1 parent f4e3611 commit 3a62714

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

examples/reload.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
var path = require('path')
3+
, log4js = require('../lib/log4js');
4+
5+
log4js.configure(
6+
// config reloading only works with file-based config (obvs)
7< 8000 /code>+
path.join(__dirname, '../test/tape/test-config.json'),
8+
{ reloadSecs: 10 }
9+
);
10+
11+
log4js.getLogger('testing').info("Just testing");
12+
log4js.shutdown(function() {
13+
//callback gets you notified when log4js has finished shutting down.
14+
});

lib/log4js.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ function shutdown(cb) {
452452
// not being able to be drained because of run-away log writes.
453453
loggerModule.disableAllLogWrites();
454454

455+
//turn off config reloading
456+
if (configState.timerId) {
457+
clearInterval(configState.timerId);
458+
}
459+
455460
// Call each of the shutdown functions in parallel
456461
var completed = 0;
457462
var error;

test/tape/reload-shutdown-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
var test = require('tape')
3+
, path = require('path')
4+
, sandbox = require('sandboxed-module');
5+
6+
test('Reload configuration shutdown hook', function(t) {
7+
var timerId
8+
, log4js = sandbox.require(
9+
'../../lib/log4js',
10+
{
11+
globals: {
12+
clearInterval: function(id) {
13+
timerId = id;
14+
},
15+
setInterval: function(fn, time) {
16+
return "1234";
17+
}
18+
}
19+
}
20+
);
21+
22+
log4js.configure(
23+
path.join(__dirname, 'test-config.json'),
24+
{ reloadSecs: 30 }
25+
);
26+
27+
t.plan(1);
28+
log4js.shutdown(function() {
29+
t.equal(timerId, "1234", "Shutdown should clear the reload timer");
30+
t.end();
31+
});
32+
33+
});

test/tape/test-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"appenders": [
3+
{ "type": "stdout" }
4+
]
5+
}

0 commit comments

Comments
 (0)
0