mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-11 02:38:59 +08:00
add more query log for dev env
This commit is contained in:
17
src/util.js
17
src/util.js
@@ -1,6 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.polyfill = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.PENDING = exports.UP = exports.DOWN = exports.appName = void 0;
|
||||
exports.TimeLogger = exports.polyfill = exports.debug = exports.ucfirst = exports.sleep = exports.flipStatus = exports.PENDING = exports.UP = exports.DOWN = exports.appName = exports.isDev = void 0;
|
||||
const dayjs = require("dayjs");
|
||||
exports.isDev = process.env.NODE_ENV === "development";
|
||||
exports.appName = "Uptime Kuma";
|
||||
exports.DOWN = 0;
|
||||
exports.UP = 1;
|
||||
@@ -28,7 +30,7 @@ function ucfirst(str) {
|
||||
}
|
||||
exports.ucfirst = ucfirst;
|
||||
function debug(msg) {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
if (exports.isDev) {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
@@ -44,3 +46,14 @@ function polyfill() {
|
||||
}
|
||||
}
|
||||
exports.polyfill = polyfill;
|
||||
class TimeLogger {
|
||||
constructor() {
|
||||
this.startTime = dayjs().valueOf();
|
||||
}
|
||||
print(name) {
|
||||
if (exports.isDev) {
|
||||
console.log(name + ": " + (dayjs().valueOf() - this.startTime) + "ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.TimeLogger = TimeLogger;
|
||||
|
19
src/util.ts
19
src/util.ts
@@ -4,6 +4,9 @@
|
||||
// Frontend uses util.ts
|
||||
// Need to run "tsc" to compile if there are any changes.
|
||||
|
||||
import * as dayjs from "dayjs";
|
||||
|
||||
export const isDev = process.env.NODE_ENV === "development";
|
||||
export const appName = "Uptime Kuma";
|
||||
export const DOWN = 0;
|
||||
export const UP = 1;
|
||||
@@ -39,7 +42,7 @@ export function ucfirst(str) {
|
||||
}
|
||||
|
||||
export function debug(msg) {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
if (isDev) {
|
||||
console.log(msg);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +55,7 @@ export function polyfill() {
|
||||
* @license MIT
|
||||
*/
|
||||
if (!String.prototype.replaceAll) {
|
||||
String.prototype.replaceAll = function(str, newStr) {
|
||||
String.prototype.replaceAll = function (str, newStr) {
|
||||
|
||||
// If a regex pattern
|
||||
if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") {
|
||||
@@ -65,3 +68,15 @@ export function polyfill() {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class TimeLogger {
|
||||
constructor() {
|
||||
this.startTime = dayjs().valueOf();
|
||||
}
|
||||
|
||||
print(name) {
|
||||
if (isDev) {
|
||||
console.log(name + ": " + (dayjs().valueOf() - this.startTime) + "ms")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user