Buffer the logging until the hook is ready, will prevent lost logs
This commit is contained in:
parent
ced570413c
commit
8b376eb46e
@ -23,7 +23,7 @@ function deserializeLoggingEvent(loggingEvent) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createAppender(hookioOptions) {
|
function initHook(hookioOptions) {
|
||||||
var loggerHook;
|
var loggerHook;
|
||||||
if (hookioOptions.mode === 'master') {
|
if (hookioOptions.mode === 'master') {
|
||||||
// Start the master hook, handling the actual logging
|
// Start the master hook, handling the actual logging
|
||||||
@ -33,11 +33,32 @@ function createAppender(hookioOptions) {
|
|||||||
loggerHook = new Hook(hookioOptions);
|
loggerHook = new Hook(hookioOptions);
|
||||||
}
|
}
|
||||||
loggerHook.start();
|
loggerHook.start();
|
||||||
|
return loggerHook;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBufferedHook(hook, eventName) {
|
||||||
|
var hookBuffer = [];
|
||||||
|
var hookReady = false;
|
||||||
|
hook.on('hook::ready', function emptyBuffer() {
|
||||||
|
hookBuffer.forEach(function logBufferItem(loggingEvent) {
|
||||||
|
hook.emit(eventName, loggingEvent);
|
||||||
|
})
|
||||||
|
hookReady = true;
|
||||||
|
});
|
||||||
|
|
||||||
var loggerEvent = hookioOptions.name + '::log';
|
|
||||||
return function log(loggingEvent) {
|
return function log(loggingEvent) {
|
||||||
loggerHook.emit(loggerEvent, loggingEvent);
|
if (hookReady) {
|
||||||
};
|
hook.emit(eventName, loggingEvent);
|
||||||
|
} else {
|
||||||
|
hookBuffer.push(loggingEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAppender(hookioOptions) {
|
||||||
|
var loggerHook = initHook(hookioOptions);
|
||||||
|
var loggerEvent = hookioOptions.name + '::log';
|
||||||
|
return getBufferedHook(loggerHook, loggerEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure(config) {
|
function configure(config) {
|
||||||
|
Loading…
Reference in New Issue
Block a user