From 944bbe77ff25487fbfd217e32f392a0ec7c898e2 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Fri, 2 Sep 2022 14:17:36 +0100 Subject: [PATCH] Logging fixes (#467) * Log fatal to console if we haven't configured logging * Move token store load up * Fix logging typo * Fix everything logging at debug * changelog * Make private --- changelog.d/467.bugfix | 1 + src/App/BridgeApp.ts | 7 ++++++- src/Bridge.ts | 2 +- src/LogWrapper.ts | 15 +++++++++++---- 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 changelog.d/467.bugfix diff --git a/changelog.d/467.bugfix b/changelog.d/467.bugfix new file mode 100644 index 00000000..95ec76e5 --- /dev/null +++ b/changelog.d/467.bugfix @@ -0,0 +1 @@ +Fixed issue where log lines would only be outputted when the `logging.level` is `debug`. \ No newline at end of file diff --git a/src/App/BridgeApp.ts b/src/App/BridgeApp.ts index c4cd38a0..01a6b8ce 100644 --- a/src/App/BridgeApp.ts +++ b/src/App/BridgeApp.ts @@ -49,6 +49,11 @@ async function start() { } start().catch((ex) => { - log.error("BridgeApp encountered an error and has stopped:", ex); + if (LogWrapper.configured) { + log.error("BridgeApp encountered an error and has stopped:", ex); + } else { + // eslint-disable-next-line no-console + console.error("BridgeApp encountered an error and has stopped", ex); + } process.exit(1); }); diff --git a/src/Bridge.ts b/src/Bridge.ts index 739e60e8..b256b103 100644 --- a/src/Bridge.ts +++ b/src/Bridge.ts @@ -88,6 +88,7 @@ export class Bridge { public async start() { log.info('Starting up'); + await this.tokenStore.load(); await this.storage.connect?.(); await this.queue.connect?.(); @@ -140,7 +141,6 @@ export class Bridge { } - await this.tokenStore.load(); const connManager = this.connectionManager = new ConnectionManager(this.as, this.config, this.tokenStore, this.commentProcessor, this.messageClient, this.storage, this.github); diff --git a/src/LogWrapper.ts b/src/LogWrapper.ts index 74cc3697..13ee66db 100644 --- a/src/LogWrapper.ts +++ b/src/LogWrapper.ts @@ -29,6 +29,12 @@ interface HookshotLogInfo extends winston.Logform.TransformableInfo { } export default class LogWrapper { + private static isConfigured: boolean; + + public static get configured() { + return this.isConfigured; + } + static formatMsgTypeArray(...data: MsgType[]): string { data = data.flat(); return data.map(obj => { @@ -144,6 +150,7 @@ export default class LogWrapper { LogService.setLevel(LogLevel.fromString(cfg.level)); LogService.debug("LogWrapper", "Reconfigured logging"); + LogWrapper.isConfigured = true; } constructor(private module: string) { } @@ -154,7 +161,7 @@ export default class LogWrapper { * @param {*[]} messageOrObject The data to log */ public debug(...messageOrObject: MsgType[]) { - LogWrapper.winstonLog.debug("debug", { module: this.module, data: messageOrObject }); + LogWrapper.winstonLog.log("debug", { module: this.module, data: messageOrObject }); } /** @@ -162,7 +169,7 @@ export default class LogWrapper { * @param {*[]} messageOrObject The data to log */ public error(...messageOrObject: MsgType[]) { - LogWrapper.winstonLog.debug("error", { module: this.module, data: messageOrObject }); + LogWrapper.winstonLog.log("error", { module: this.module, data: messageOrObject }); } /** @@ -170,7 +177,7 @@ export default class LogWrapper { * @param {*[]} messageOrObject The data to log */ public info(...messageOrObject: MsgType[]) { - LogWrapper.winstonLog.debug("info", { module: this.module, data: messageOrObject }); + LogWrapper.winstonLog.log("info", { module: this.module, data: messageOrObject }); } /** @@ -178,6 +185,6 @@ export default class LogWrapper { * @param {*[]} messageOrObject The data to log */ public warn(...messageOrObject: MsgType[]) { - LogWrapper.winstonLog.debug("warn", { module: this.module, data: messageOrObject }); + LogWrapper.winstonLog.log("warn", { module: this.module, data: messageOrObject }); } }