From 30a1fd9013cbdc73550842c7fc24f45bdcdcea47 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 21 Apr 2024 10:19:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=A5=E9=94=99=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/common/logger.ts | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/core/common/logger.ts b/src/core/common/logger.ts index 3eb1939..652b27a 100644 --- a/src/core/common/logger.ts +++ b/src/core/common/logger.ts @@ -1,3 +1,5 @@ +import { debounce } from 'lodash-es'; + export const enum LogLevel { /** 输出所有,包括日志 */ LOG, @@ -9,6 +11,29 @@ export const enum LogLevel { ERROR } +let logTip: HTMLSpanElement; +if (!main.replayChecking) { + const tip = document.createElement('span'); + logTip = tip; + tip.style.position = 'fixed'; + tip.style.right = '0'; + tip.style.bottom = '0'; + tip.style.height = '20px'; + tip.style.width = 'auto'; + tip.style.textAlign = 'right'; + tip.style.padding = '0 5px'; + tip.style.fontSize = '16px'; + tip.style.fontFamily = 'Arial'; + tip.style.display = 'none'; + tip.style.margin = '2px'; + document.body.appendChild(tip); +} + +const hideTipText = debounce(() => { + if (main.replayChecking) return; + logTip.style.display = 'none'; +}, 5000); + export class Logger { level: LogLevel = LogLevel.LOG; @@ -32,6 +57,12 @@ export class Logger { error(code: number, text: string) { if (this.level <= LogLevel.ERROR) { console.error(`[ERROR Code ${code}] ${text}`); + if (!main.replayChecking) { + logTip.style.color = 'lightcoral'; + logTip.style.display = 'block'; + logTip.textContent = `Error thrown, please check in console.`; + hideTipText(); + } } } @@ -43,6 +74,12 @@ export class Logger { severe(code: number, text: string) { if (this.level <= LogLevel.SEVERE_WARNING) { console.warn(`[SEVERE WARNING Code ${code}] ${text}`); + if (!main.replayChecking) { + logTip.style.color = 'goldenrod'; + logTip.style.display = 'block'; + logTip.textContent = `Severe warning thrown, please check in console.`; + hideTipText(); + } } } @@ -54,6 +91,12 @@ export class Logger { warn(code: number, text: string) { if (this.level <= LogLevel.WARNING) { console.warn(`[WARNING Code ${code}] ${text}`); + if (!main.replayChecking) { + logTip.style.color = 'gold'; + logTip.style.display = 'block'; + logTip.textContent = `Warning thrown, please check in console.`; + hideTipText(); + } } }