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
This commit is contained in:
Will Hunt 2022-09-02 14:17:36 +01:00 committed by GitHub
parent 9d7e6adcd4
commit 944bbe77ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 6 deletions

1
changelog.d/467.bugfix Normal file
View File

@ -0,0 +1 @@
Fixed issue where log lines would only be outputted when the `logging.level` is `debug`.

View File

@ -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);
});

View File

@ -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);

View File

@ -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 });
}
}