mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
public commit
This commit is contained in:
36
app/src/core/utils/DebugLogger.ts
Normal file
36
app/src/core/utils/DebugLogger.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
export class DebugLogger {
|
||||
public _context: string[] = [];
|
||||
_enabled: boolean = true;
|
||||
private readonly id = Math.random().toString(36).substr(2, 9);
|
||||
private last: number = 0;
|
||||
|
||||
constructor(enabled: boolean = true) {
|
||||
this._enabled = enabled;
|
||||
}
|
||||
|
||||
context(context: string) {
|
||||
//console.log("[ settings context ]", context, this._context);
|
||||
this._context.push(context);
|
||||
return this;
|
||||
}
|
||||
|
||||
clear() {
|
||||
//console.log("[ clear context ]", this._context.pop(), this._context);
|
||||
this._context.pop();
|
||||
return this;
|
||||
}
|
||||
|
||||
log(...args: any[]) {
|
||||
if (!this._enabled) return this;
|
||||
|
||||
const now = performance.now();
|
||||
const time = Number.parseInt(String(now - this.last));
|
||||
const indents = " ".repeat(this._context.length);
|
||||
const context =
|
||||
this._context.length > 0 ? `[${this._context[this._context.length - 1]}]` : "";
|
||||
console.log(indents, context, time, ...args);
|
||||
|
||||
this.last = now;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user