All files / src/Ice Logger.js

77.02% Statements 57/74
85.71% Branches 6/7
55.55% Functions 5/9
77.02% Lines 57/74

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 7541x 41x 41x 41x 41x 41x 55x 55x 55x     55x 55x 55x 55x 55x 55x 55x 55x 55x 55x 55x 41x 41x     41x 41x 14915x 14915x 14915x 14915x 14915x 14915x 14915x 14915x 14915x 14915x 41x 41x 2x 2x 2x 2x 2x 2x 2x 2x 2x 41x 41x                   41x 41x     41x 41x     41x 41x 14917x 14917x 14917x 41x  
// Copyright (c) ZeroC, Inc.
 
const formatMessage = message => message.join("").replace(/\n/g, "\n   ");
 
export class Logger {
    constructor(prefix) {
        if (prefix !== undefined && prefix.length > 0) {
            this._prefix = `${prefix}: `;
        } else {
            this._prefix = "";
        }
 
        this._dateformat = {
            year: "numeric",
            month: "numeric",
            day: "numeric",
            hour: "numeric",
            minute: "numeric",
            second: "numeric",
            hour12: false,
        };
    }
 
    print(message) {
        this.write(message);
    }
 
    trace(category, message) {
        const s = [];
        s.push("-- ");
        s.push(this.timestamp());
        s.push(" ");
        s.push(this._prefix);
        s.push(category);
        s.push(": ");
        s.push(message);
        this.write(formatMessage(s));
    }
 
    warning(message) {
        const s = [];
        s.push("-! ");
        s.push(this.timestamp());
        s.push(" ");
        s.push(this._prefix);
        s.push("warning: ");
        s.push(message);
        this.write(formatMessage(s));
    }
 
    error(message) {
        const s = [];
        s.push("!! ");
        s.push(this.timestamp());
        s.push(" ");
        s.push(this._prefix);
        s.push("error: ");
        s.push(message);
        this.write(formatMessage(s));
    }
 
    cloneWithPrefix(prefix) {
        return new Logger(prefix);
    }
 
    write(message) {
        console.log(message);
    }
 
    timestamp() {
        const d = new Date();
        return d.toLocaleString("en-US", this._dateformat) + "." + d.getMilliseconds();
    }
}