mframejs
Version:
simple framework
48 lines (37 loc) • 971 B
text/typescript
let loggerActive = false;
let id = 10000;
let defaultLog: any;
/**
* Simple logger
*
*/
export class Logger {
private name: string;
private category: string;
private id: number;
constructor(name: string, category?: string) {
this.id = id;
id++;
this.name = name;
this.category = category || 'unamed';
}
public static getLogger(name: string, category?: string): Logger {
if (loggerActive) {
return new Logger(name, category);
} else {
return defaultLog;
}
}
public static enable() {
loggerActive = true;
}
public static disable() {
loggerActive = false;
}
public log(...msg: any[]) {
if (loggerActive) {
console.warn(`Log[${this.id}] - [${this.category}] - [${this.name}] `, msg.join(' - '));
}
}
}
defaultLog = new Logger('na', 'na');