Fix hanging "Clear All Data" on Windows

This commit is contained in:
Fedor Indutny 2021-05-13 13:54:54 -07:00 committed by Scott Nonnenberg
parent 03eaa9eb3e
commit fe505a7f2f
8 changed files with 58 additions and 14 deletions

View file

@ -38,6 +38,7 @@ declare global {
}
let globalLogger: undefined | pinoms.Logger;
let shouldRestart = false;
const isRunningFromConsole =
Boolean(process.stdout.isTTY) ||
@ -74,13 +75,16 @@ export async function initialize(): Promise<pinoms.Logger> {
rotate: 3,
});
stream.on('close', () => {
const onClose = () => {
globalLogger = undefined;
});
stream.on('error', () => {
globalLogger = undefined;
});
if (shouldRestart) {
initialize();
}
};
stream.on('close', onClose);
stream.on('error', onClose);
const streams: pinoms.Streams = [];
streams.push({ stream });
@ -109,6 +113,9 @@ export async function initialize(): Promise<pinoms.Logger> {
});
ipc.on('delete-all-logs', async event => {
// Restart logging when the streams will close
shouldRestart = true;
try {
await deleteAllLogs(logPath);
} catch (error) {

View file

@ -101,6 +101,11 @@ function fetch(): Promise<string> {
}
let globalLogger: undefined | pino.Logger;
let shouldRestart = false;
export function beforeRestart(): void {
shouldRestart = true;
}
export function initialize(): void {
if (globalLogger) {
@ -114,13 +119,16 @@ export function initialize(): void {
rotate: 3,
});
stream.on('close', () => {
const onClose = () => {
globalLogger = undefined;
});
stream.on('error', () => {
globalLogger = undefined;
});
if (shouldRestart) {
initialize();
}
};
stream.on('close', onClose);
stream.on('error', onClose);
globalLogger = pino(
{