diff --git a/server/database.js b/server/database.js index b23f56db3..46e6ecaf3 100644 --- a/server/database.js +++ b/server/database.js @@ -515,12 +515,12 @@ class Database { let title = await Settings.get("title"); if (title) { - console.log("Migrating Status Page"); + log.info("database", "Migrating Status Page"); let statusPageCheck = await R.findOne("status_page", " slug = 'default' "); if (statusPageCheck !== null) { - console.log("Migrating Status Page - Skip, default slug record is already existing"); + log.info("database", "Migrating Status Page - Skip, default slug record is already existing"); return; } @@ -566,7 +566,7 @@ class Database { await Settings.set("entryPage", "statusPage-default", "general"); } - console.log("Migrating Status Page - Done"); + log.info("database", "Migrating Status Page - Done"); } } diff --git a/server/monitor-types/real-browser-monitor-type.js b/server/monitor-types/real-browser-monitor-type.js index f1219af18..ce3abcb2d 100644 --- a/server/monitor-types/real-browser-monitor-type.js +++ b/server/monitor-types/real-browser-monitor-type.js @@ -63,7 +63,7 @@ if (process.platform === "win32") { * @returns {Promise} The executable is allowed? */ async function isAllowedChromeExecutable(executablePath) { - console.log(config.args); + log.info("Chromium", config.args); if (config.args["allow-all-chrome-exec"] || process.env.UPTIME_KUMA_ALLOW_ALL_CHROME_EXEC === "1") { return true; } @@ -102,7 +102,8 @@ async function getBrowser() { */ async function getRemoteBrowser(remoteBrowserID, userId) { let remoteBrowser = await RemoteBrowser.get(remoteBrowserID, userId); - log.debug("MONITOR", `Using remote browser: ${remoteBrowser.name} (${remoteBrowser.id})`); + log.debug("Chromium", `Using remote browser: ${remoteBrowser.name} (${remoteBrowser.id})`); + browser = chromium.connect(remoteBrowser.url); browser = await chromium.connect(remoteBrowser.url); return browser; } diff --git a/server/notification-providers/slack.js b/server/notification-providers/slack.js index 26d8512dd..16246775e 100644 --- a/server/notification-providers/slack.js +++ b/server/notification-providers/slack.js @@ -2,6 +2,7 @@ const NotificationProvider = require("./notification-provider"); const axios = require("axios"); const { getMonitorRelativeURL, UP } = require("../../src/util"); const { Settings } = require("../settings"); +const { log } = require("../../src/util"); class Slack extends NotificationProvider { name = "slack"; @@ -17,10 +18,10 @@ class Slack extends NotificationProvider { let currentPrimaryBaseURL = await Settings.get("primaryBaseURL"); if (!currentPrimaryBaseURL) { - console.log("Move the url to be the primary base URL"); + log.error("notification", "Move the url to be the primary base URL"); await Settings.set("primaryBaseURL", url, "general"); } else { - console.log("Already there, no need to move the primary base URL"); + log.debug("notification", "Already there, no need to move the primary base URL"); } } diff --git a/server/server.js b/server/server.js index 44f794c4e..3579df5d2 100644 --- a/server/server.js +++ b/server/server.js @@ -1464,7 +1464,7 @@ let needSetup = false; }); } catch (e) { - console.error(e); + log.error("server", e); callback({ ok: false, diff --git a/server/socket-handlers/api-key-socket-handler.js b/server/socket-handlers/api-key-socket-handler.js index f76b90991..1394f8044 100644 --- a/server/socket-handlers/api-key-socket-handler.js +++ b/server/socket-handlers/api-key-socket-handler.js @@ -60,7 +60,7 @@ module.exports.apiKeySocketHandler = (socket) => { ok: true, }); } catch (e) { - console.error(e); + log.error("apikeys", e); callback({ ok: false, msg: e.message, diff --git a/server/socket-handlers/cloudflared-socket-handler.js b/server/socket-handlers/cloudflared-socket-handler.js index 0a8d06066..1cd0c53d0 100644 --- a/server/socket-handlers/cloudflared-socket-handler.js +++ b/server/socket-handlers/cloudflared-socket-handler.js @@ -101,11 +101,11 @@ module.exports.autoStart = async (token) => { } else { // Override the current token via args or env var await Settings.set("cloudflaredTunnelToken", token); - console.log("Use cloudflared token from args or env var"); + log.info("cloudflare", "Use cloudflared token from args or env var"); } if (token) { - console.log("Start cloudflared"); + log.info("cloudflare", "Start cloudflared"); cloudflared.token = token; cloudflared.start(); } diff --git a/server/socket-handlers/maintenance-socket-handler.js b/server/socket-handlers/maintenance-socket-handler.js index 7de13fe57..201014c22 100644 --- a/server/socket-handlers/maintenance-socket-handler.js +++ b/server/socket-handlers/maintenance-socket-handler.js @@ -67,7 +67,7 @@ module.exports.maintenanceSocketHandler = (socket) => { }); } catch (e) { - console.error(e); + log.error("maintenance", e); callback({ ok: false, msg: e.message, @@ -177,7 +177,7 @@ module.exports.maintenanceSocketHandler = (socket) => { ok: true, }); } catch (e) { - console.error(e); + log.error("maintenance", e); callback({ ok: false, msg: e.message, @@ -201,7 +201,7 @@ module.exports.maintenanceSocketHandler = (socket) => { }); } catch (e) { - console.error(e); + log.error("maintenance", e); callback({ ok: false, msg: e.message, @@ -225,7 +225,7 @@ module.exports.maintenanceSocketHandler = (socket) => { }); } catch (e) { - console.error(e); + log.error("maintenance", e); callback({ ok: false, msg: e.message, diff --git a/server/socket-handlers/status-page-socket-handler.js b/server/socket-handlers/status-page-socket-handler.js index c11a4d2b3..cf0accc23 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -292,7 +292,7 @@ module.exports.statusPageSocketHandler = (socket) => { }); } catch (error) { - console.error(error); + log.error("socket", error); callback({ ok: false, msg: error.message, diff --git a/src/util.js b/src/util.js index df89cf92b..ab8225339 100644 --- a/src/util.js +++ b/src/util.js @@ -8,17 +8,34 @@ // Backend uses the compiled file util.js // Frontend uses util.ts */ +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.sleep = exports.flipStatus = exports.badgeConstants = exports.CONSOLE_STYLE_BgGray = exports.CONSOLE_STYLE_BgWhite = exports.CONSOLE_STYLE_BgCyan = exports.CONSOLE_STYLE_BgMagenta = exports.CONSOLE_STYLE_BgBlue = exports.CONSOLE_STYLE_BgYellow = exports.CONSOLE_STYLE_BgGreen = exports.CONSOLE_STYLE_BgRed = exports.CONSOLE_STYLE_BgBlack = exports.CONSOLE_STYLE_FgPink = exports.CONSOLE_STYLE_FgBrown = exports.CONSOLE_STYLE_FgViolet = exports.CONSOLE_STYLE_FgLightBlue = exports.CONSOLE_STYLE_FgLightGreen = exports.CONSOLE_STYLE_FgOrange = exports.CONSOLE_STYLE_FgGray = exports.CONSOLE_STYLE_FgWhite = exports.CONSOLE_STYLE_FgCyan = exports.CONSOLE_STYLE_FgMagenta = exports.CONSOLE_STYLE_FgBlue = exports.CONSOLE_STYLE_FgYellow = exports.CONSOLE_STYLE_FgGreen = exports.CONSOLE_STYLE_FgRed = exports.CONSOLE_STYLE_FgBlack = exports.CONSOLE_STYLE_Hidden = exports.CONSOLE_STYLE_Reverse = exports.CONSOLE_STYLE_Blink = exports.CONSOLE_STYLE_Underscore = exports.CONSOLE_STYLE_Dim = exports.CONSOLE_STYLE_Bright = exports.CONSOLE_STYLE_Reset = exports.MIN_INTERVAL_SECOND = exports.MAX_INTERVAL_SECOND = exports.SQL_DATETIME_FORMAT_WITHOUT_SECOND = exports.SQL_DATETIME_FORMAT = exports.SQL_DATE_FORMAT = exports.STATUS_PAGE_MAINTENANCE = exports.STATUS_PAGE_PARTIAL_DOWN = exports.STATUS_PAGE_ALL_UP = exports.STATUS_PAGE_ALL_DOWN = exports.MAINTENANCE = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isNode = exports.isDev = void 0; -exports.evaluateJsonQuery = exports.intHash = exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = void 0; -exports.intHash = exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.debug = exports.ucfirst = void 0; +exports.evaluateJsonQuery = exports.intHash = exports.localToUTC = exports.utcToLocal = exports.utcToISODateTime = exports.isoToUTCDateTime = exports.parseTimeFromTimeObject = exports.parseTimeObject = exports.getMaintenanceRelativeURL = exports.getMonitorRelativeURL = exports.genSecret = exports.getCryptoRandomInt = exports.getRandomInt = exports.getRandomArbitrary = exports.TimeLogger = exports.polyfill = exports.log = exports.ucfirst = void 0; const dayjs_1 = __importDefault(require("dayjs")); -const dayjs = require("dayjs"); -const jsonata = require("jsonata"); +const jsonata = __importStar(require("jsonata")); exports.isDev = process.env.NODE_ENV === "development"; exports.isNode = typeof process !== "undefined" && ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node); exports.appName = "Uptime Kuma"; @@ -66,7 +83,6 @@ exports.CONSOLE_STYLE_BgMagenta = "\x1b[45m"; exports.CONSOLE_STYLE_BgCyan = "\x1b[46m"; exports.CONSOLE_STYLE_BgWhite = "\x1b[47m"; exports.CONSOLE_STYLE_BgGray = "\x1b[100m"; - const consoleModuleColors = [ exports.CONSOLE_STYLE_FgCyan, exports.CONSOLE_STYLE_FgGreen, @@ -125,10 +141,6 @@ function ucfirst(str) { return firstLetter.toUpperCase() + str.substr(1); } exports.ucfirst = ucfirst; -function debug(msg) { - exports.log.log("", msg, "debug"); -} -exports.debug = debug; class Logger { constructor() { this.hideLog = { @@ -157,7 +169,6 @@ class Logger { return; } module = module.toUpperCase(); - level = level.toUpperCase(); let now; if (dayjs_1.default.tz) { now = dayjs_1.default.tz(new Date()).format(); @@ -231,23 +242,23 @@ class Logger { } } info(module, msg) { - this.log(module, msg, "info"); + this.log(module, msg, "INFO"); } warn(module, msg) { - this.log(module, msg, "warn"); + this.log(module, msg, "WARN"); } error(module, msg) { - this.log(module, msg, "error"); + this.log(module, msg, "ERROR"); } debug(module, msg) { - this.log(module, msg, "debug"); + this.log(module, msg, "DEBUG"); } exception(module, exception, msg) { let finalMessage = exception; if (msg) { finalMessage = `${msg}: ${exception}`; } - this.log(module, finalMessage, "error"); + this.log(module, finalMessage, "ERROR"); } } exports.log = new Logger(); @@ -458,4 +469,4 @@ async function evaluateJsonQuery(data, jsonPath, jsonPathOperator, expectedValue throw new Error(`Error evaluating JSON query: ${err.message}. Response from server was: ${response}`); } } -exports.evaluateJsonQuery = evaluateJsonQuery; \ No newline at end of file +exports.evaluateJsonQuery = evaluateJsonQuery; diff --git a/src/util.ts b/src/util.ts index 85ef7ee99..718db6150 100644 --- a/src/util.ts +++ b/src/util.ts @@ -201,12 +201,13 @@ class Logger { /** * Write a message to the log + * @private * @param module The module the log comes from * @param msg Message to write - * @param level Log level. One of INFO, WARN, ERROR, DEBUG or can be customized. + * @param level {"INFO"|"WARN"|"ERROR"|"DEBUG"} Log level * @returns {void} */ - log(module: string, msg: any, level: string) { + log(module: string, msg: unknown, level: "INFO"|"WARN"|"ERROR"|"DEBUG"): void { if (level === "DEBUG" && !isDev) { return; } @@ -216,7 +217,6 @@ class Logger { } module = module.toUpperCase(); - level = level.toUpperCase(); let now; if (dayjs.tz) { @@ -303,8 +303,8 @@ class Logger { * @param msg Message to write * @returns {void} */ - info(module: string, msg: unknown) { - this.log(module, msg, "info"); + info(module: string, msg: string): void { + this.log(module, msg, "INFO"); } /** @@ -313,8 +313,8 @@ class Logger { * @param msg Message to write * @returns {void} */ - warn(module: string, msg: unknown) { - this.log(module, msg, "warn"); + warn(module: string, msg: string): void { + this.log(module, msg, "WARN"); } /** @@ -323,8 +323,8 @@ class Logger { * @param msg Message to write * @returns {void} */ - error(module: string, msg: unknown) { - this.log(module, msg, "error"); + error(module: string, msg: string): void { + this.log(module, msg, "ERROR"); } /** @@ -333,8 +333,8 @@ class Logger { * @param msg Message to write * @returns {void} */ - debug(module: string, msg: unknown) { - this.log(module, msg, "debug"); + debug(module: string, msg: string): void { + this.log(module, msg, "DEBUG"); } /** @@ -351,7 +351,7 @@ class Logger { finalMessage = `${msg}: ${exception}`; } - this.log(module, finalMessage, "error"); + this.log(module, finalMessage, "ERROR"); } } @@ -395,7 +395,7 @@ export class TimeLogger { * @param name Name of monitor * @returns {void} */ - print(name: string) { + print(name: string): void { if (isDev && process.env.TIMELOGGER === "1") { console.log(name + ": " + (dayjs().valueOf() - this.startTime) + "ms"); }