Repository: louislam/uptime-kuma
File: src/util.js (JavaScript)

Code before:
            this.debug("server", "UPTIME_KUMA_HIDE_LOG is set");
            this.debug("server", this.hideLog);
        }
    }
    log(module, msg, level) {
        if (level === "DEBUG" && !exports.isDev) {
            return;
        }
        if (this.hideLog[level] && this.hideLog[level].includes(module.toLowerCase())) {
            return;
        }
        let now;
        if (dayjs_1.default.tz) {
            now = dayjs_1.default.tz(new Date()).format();
        }
        else {
            now = (0, dayjs_1.default)().format();
        }
        const structuredLogging = process.env.UPTIME_KUMA_LOG_FORMAT === "json";
        const levelColor = consoleLevelColors[level];
        const moduleColor = consoleModuleColors[intHash(module, consoleModuleColors.length)];
        let timePart = now;
        let modulePart = module;
        let levelPart = level;
        let msgPart = msg;
        if (!structuredLogging) {
            module = module.toUpperCase();
            if (exports.isNode) {
                switch (level) {
                    case "DEBUG":
                        timePart = exports.CONSOLE_STYLE_FgGray + now + exports.CONSOLE_STYLE_Reset;
                        break;
                    default:
                        timePart = exports.CONSOLE_STYLE_FgCyan + now + exports.CONSOLE_STYLE_Reset;
                        break;
                }
                modulePart = "[" + moduleColor + module + exports.CONSOLE_STYLE_Reset + "]";
                levelPart = levelColor + `${level}:` + exports.CONSOLE_STYLE_Reset;
                switch (level) {
                    case "ERROR":
                        if (typeof msg === "string") {
                            msgPart = exports.CONSOLE_STYLE_FgRed + msg + exports.CONSOLE_STYLE_Reset;
                        }
                        break;
                    case "DEBUG":
                        if (typeof msg === "string") {
                            msgPart = exports.CONSOLE_STYLE_FgGray + msg + exports.CONSOLE_STYLE_Reset;
                        }
                        break;
                    default:
                        break;

Review comment (suggestion):
lets change this to the following, which is a bit simpler to read and review

Please also change the rest of the code accordingly ^^

```suggestion
        if (process.env.UPTIME_KUMA_LOG_FORMAT === "json") {
            console.log(JSON.stringify({
                time: timePart,
                module: modulePart,
                level: levelPart,
                msg: typeof msg === "string" ? msg : JSON.stringify(msg),
            }));
            return;
        }
```

Code after:
            this.debug("server", "UPTIME_KUMA_HIDE_LOG is set");
            this.debug("server", this.hideLog);
        }
    }
    log(module, msg, level) {
        if (level === "DEBUG" && !exports.isDev) {
            return;
        }
        if (this.hideLog[level] && this.hideLog[level].includes(module.toLowerCase())) {
            return;
        }
        let now;
        if (dayjs_1.default.tz) {
            now = dayjs_1.default.tz(new Date()).format();
        }
        else {
            now = (0, dayjs_1.default)().format();
        }
        const levelColor = consoleLevelColors[level];
        const moduleColor = consoleModuleColors[intHash(module, consoleModuleColors.length)];
        let timePart = now;
        let modulePart = module;
        let levelPart = level;
        let msgPart = msg;
        if (process.env.UPTIME_KUMA_LOG_FORMAT === "json") {
            console.log(JSON.stringify({
                time: timePart,
                module: modulePart,
                level: levelPart,
                msg: typeof msg === "string" ? msg : JSON.stringify(msg),
            }));
            return;
        }
        module = module.toUpperCase();
        if (exports.isNode) {
            switch (level) {
                case "DEBUG":
                    timePart = exports.CONSOLE_STYLE_FgGray + now + exports.CONSOLE_STYLE_Reset;
                    break;
                default:
                    timePart = exports.CONSOLE_STYLE_FgCyan + now + exports.CONSOLE_STYLE_Reset;
                    break;
            }
            modulePart = "[" + moduleColor + module + exports.CONSOLE_STYLE_Reset + "]";
            levelPart = levelColor + `${level}:` + exports.CONSOLE_STYLE_Reset;
            switch (level) {
                case "ERROR":
                    if (typeof msg === "string") {
                        msgPart = exports.CONSOLE_STYLE_FgRed + msg + exports.CONSOLE_STYLE_Reset;
                    }
                    break;