All files / mframejs/utils logger.ts

69.23% Statements 9/13
50% Branches 1/2
60% Functions 3/5
69.23% Lines 9/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  29x 29x             29x           29x 29x 29x 29x             1436x                                       29x    
 
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');