Configuration parameter to one location and configurable logger

This commit is contained in:
dennis committed 2023-02-04 20:16:26 +01:00
1 parent a396e49c8e
commit 505b8b0a4a
5 files changed
+214 -80

No files matched your search

+31
View File
@@ -0,0 +1,31 @@
import {Logger} from 'homebridge';
export class Logging {
private readonly logHandler: Logger;
private readonly prefix: string;
private readonly isDebug: boolean;
constructor(
log: Logger,
prefix: string,
isDebug: boolean,
) {
this.logHandler = log;
this.prefix = prefix;
this.isDebug = isDebug;
}
private msgPrefix() {
return '[' + this.prefix + ']';
}
log(...parts: any) {
this.isDebug ?
this.logHandler.debug(this.msgPrefix(), ...parts) :
this.logHandler.info(this.msgPrefix(), ...parts);
}
warn = (...parts: any) => this.logHandler.warn(this.msgPrefix(), ...parts);
error = (...parts: any) => this.logHandler.error(this.msgPrefix(), ...parts);
debug = (...parts: any) => this.logHandler.debug(this.msgPrefix(), ...parts);
}