Merge pull request #873 from log4js-node/fix-sighup-handler

Sighup handler was just nonsense
This commit is contained in:
Gareth Jones 2019-05-09 08:31:58 +10:00 committed by GitHub
commit ff198de9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 21 deletions

View File

@ -49,14 +49,14 @@ function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset
timezoneOffset, ')'
);
const writer = openTheStream(file, logSize, numBackups, options);
let writer = openTheStream(file, logSize, numBackups, options);
const app = function (loggingEvent) {
writer.write(layout(loggingEvent, timezoneOffset) + eol, 'utf8');
};
app.reopen = function () {
writer.closeTheStream(writer.openTheStream.bind(writer));
writer.end(() => { writer = openTheStream(file, logSize, numBackups, options); });
};
app.sighupHandler = function () {

View File

@ -7,42 +7,46 @@ test('file appender SIGHUP', (t) => {
let closeCalled = 0;
let openCalled = 0;
sandbox.require(
const appender = sandbox.require(
'../../lib/appenders/file',
{
requires: {
streamroller: {
RollingFileStream: function () {
this.openTheStream = function () {
RollingFileStream: class RollingFileStream {
constructor() {
openCalled++;
};
this.ended = false;
}
this.closeTheStream = function (cb) {
on() {
this.dummy = 'easier than turning off lint rule';
}
end(cb) {
this.ended = true;
closeCalled++;
if (cb) {
cb();
cb();
}
write() {
if (this.ended) {
throw new Error('write after end');
}
};
this.on = function () {
};
this.end = function () {
};
this.write = function () {
return true;
};
}
}
}
}
}
).configure({ type: 'file', filename: 'sighup-test-file' }, { basicLayout: function () {} });
).configure({ type: 'file', filename: 'sighup-test-file' }, { basicLayout: function () { return 'whatever'; } });
appender('something to log');
process.kill(process.pid, 'SIGHUP');
t.plan(2);
setTimeout(() => {
t.equal(openCalled, 1, 'open should be called once');
appender('something to log after sighup');
t.equal(openCalled, 2, 'open should be called twice');
t.equal(closeCalled, 1, 'close should be called once');
t.end();
}, 100);