Buffer the logging until the hook is ready, will prevent lost logs
This commit is contained in:
@@ -23,7 +23,7 @@ function deserializeLoggingEvent(loggingEvent) {
|
||||
};
|
||||
}
|
||||
|
||||
function createAppender(hookioOptions) {
|
||||
function initHook(hookioOptions) {
|
||||
var loggerHook;
|
||||
if (hookioOptions.mode === 'master') {
|
||||
// Start the master hook, handling the actual logging
|
||||
@@ -33,11 +33,32 @@ function createAppender(hookioOptions) {
|
||||
loggerHook = new Hook(hookioOptions);
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user