All files / src logger.ts

96.55% Statements 28/29
100% Branches 8/8
12.5% Functions 1/8
96.55% Lines 28/29

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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 1141x 1x           1x           17x   1x 1x   1x 1x   1x 1x   1x 1x   1x 1x   10x 10x   1x 1x   1x     17x 17x   17x 17x 17x 17x 17x 17x 17x                                                                                                                                  
import Environment from "./environment";
import {
    Logger as TSLogLogger,
    ILogObject as LogObject,
    TLogLevelName
} from "tslog";
 
export default class Logger {
    private logger: TSLogLogger;
 
    public constructor() {
        let minLevel: TLogLevelName;
 
        switch (Environment.getMinLogLevel()) {
            case "silly":
                minLevel = "silly"
                break;
            case "trace":
                minLevel = "trace"
                break;
            case "debug":
                minLevel = "debug"
                break;
            case "info":
                minLevel = "info"
                break;
            case "warn":
                minLevel = "warn"
                break;
            case "error":
                minLevel = "error"
                break;
            case "fatal":
                minLevel = "fatal"
                break;
            default:
                minLevel = "error";
        }
 
        minLevel = "error";
        this.logger = new TSLogLogger({ minLevel });
        // overload is required to get the real position for logging
        this.silly = this.logger.silly.bind(this.logger);
        this.trace = this.logger.trace.bind(this.logger);
        this.debug = this.logger.debug.bind(this.logger);
        this.info = this.logger.info.bind(this.logger);
        this.warn = this.logger.warn.bind(this.logger);
        this.error = this.logger.error.bind(this.logger);
        this.fatal = this.logger.fatal.bind(this.logger);
    }
 
    /**
     * Logs a silly message.
     * @param args  - Multiple log attributes that should be logged out.
     */
    public silly(...args: unknown[]): LogObject {
        /* istanbul ignore next */
        return this.logger.silly(...args);
    }
 
    /**
     * Logs a trace message.
     * @param args  - Multiple log attributes that should be logged out.
     */
    public trace(...args: unknown[]): LogObject {
        /* istanbul ignore next */
        return this.logger.trace(...args);
    }
 
    /**
     * Logs a debug message.
     * @param args  - Multiple log attributes that should be logged out.
     */
    public debug(...args: unknown[]): LogObject {
        return this.logger.debug(...args);
    }
 
    /**
     * Logs a info message.
     * @param args  - Multiple log attributes that should be logged out.
     */
    public info(...args: unknown[]): LogObject {
        /* istanbul ignore next */
        return this.logger.info(...args);
    }
 
    /**
     * Logs a warn message.
     * @param args  - Multiple log attributes that should be logged out.
     */
    public warn(...args: unknown[]): LogObject {
        /* istanbul ignore next */
        return this.logger.warn(...args);
    }
 
    /**
     * Logs a error message.
     * @param args  - Multiple log attributes that should be logged out.
     */
    public error(...args: unknown[]): LogObject {
        /* istanbul ignore next */
        return this.logger.error(...args);
    }
 
    /**
     * Logs a fatal message.
     * @param args  - Multiple log attributes that should be logged out.
     */
    public fatal(...args: unknown[]): LogObject {
        /* istanbul ignore next */
        return this.logger.fatal(...args);
    }
}