allow filtering based on log levels (#1677)

This commit is contained in:
Danish Arora 2023-10-23 13:26:35 +05:30 committed by GitHub
parent f82add16ab
commit 81b2bf46ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -67,7 +67,7 @@ export class StreamManager {
private handlePeerUpdateStreamPool = (evt: CustomEvent<PeerUpdate>): void => {
const peer = evt.detail.peer;
if (peer.protocols.includes(this.multicodec)) {
this.log.error(`Preemptively opening a stream to ${peer.id.toString()}`);
this.log.info(`Preemptively opening a stream to ${peer.id.toString()}`);
this.prepareNewStream(peer);
}
};

View File

@ -12,13 +12,9 @@ export class Logger {
}
constructor(prefix?: string) {
this._info = debug(Logger.createDebugNamespace("INFO", prefix));
this._warn = debug(Logger.createDebugNamespace("WARN", prefix));
this._error = debug(Logger.createDebugNamespace("ERROR", prefix));
this._info.log = console.info.bind(console);
this._warn.log = console.warn.bind(console);
this._error.log = console.error.bind(console);
this._info = debug(Logger.createDebugNamespace("info", prefix));
this._warn = debug(Logger.createDebugNamespace("warn", prefix));
this._error = debug(Logger.createDebugNamespace("error", prefix));
}
get info(): Debugger {
@ -32,4 +28,9 @@ export class Logger {
get error(): Debugger {
return this._error;
}
log(level: "info" | "warn" | "error", ...args: unknown[]): void {
const logger = this[level] as (...args: unknown[]) => void;
logger(...args);
}
}