mirror of
https://github.com/dtwardow/homebridge-multi-tap-switch.git
synced 2026-11-02 05:18:30 +00:00
Configuration parameter to one location and configurable logger
This commit is contained in:
1 parent
a396e49c8e
commit
505b8b0a4a
5 files changed
+214
-80
No files matched your search
@@ -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);
|
||||
}
|
||||
Reference in new issue
Block a user