From 8fbfc0202b4fd8883572b126cf4b1cc21f5fd046 Mon Sep 17 00:00:00 2001 From: moyin <244344649@qq.com> Date: Wed, 17 Dec 2025 11:03:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8DPino=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E9=85=8D=E7=BD=AE=E7=9A=84Worker=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除customPrettifiers中的箭头函数以避免DataCloneError - 修复未使用参数的TypeScript警告 - 替换已弃用的substr方法为substring --- src/core/utils/logger/logger.config.ts | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/core/utils/logger/logger.config.ts b/src/core/utils/logger/logger.config.ts index a21714e..77fc642 100644 --- a/src/core/utils/logger/logger.config.ts +++ b/src/core/utils/logger/logger.config.ts @@ -82,7 +82,7 @@ export class LoggerConfigFactory { }, // 自定义错误响应消息 - customErrorMessage: (req: any, res: any, err: any) => { + customErrorMessage: (req: any, _res: any, err: any) => { return `${req.method} ${req.url} failed: ${err.message}`; }, }, @@ -152,20 +152,7 @@ export class LoggerConfigFactory { translateTime: 'SYS:yyyy-mm-dd HH:MM:ss', ignore: 'pid,hostname', messageFormat: '{app} [{level}] {msg}', - customPrettifiers: { - time: (timestamp: any) => `🕐 ${timestamp}`, - level: (logLevel: any) => { - const levelEmojis: Record = { - 10: '🔍', // trace - 20: '🐛', // debug - 30: '📝', // info - 40: '⚠️', // warn - 50: '❌', // error - 60: '💀', // fatal - }; - return `${levelEmojis[logLevel] || '📝'} ${logLevel}`; - }, - }, + // 移除 customPrettifiers 以避免 Worker 线程序列化问题 }, level: logLevel, }, @@ -231,13 +218,13 @@ export class LoggerConfigFactory { /** * 自定义日志级别判断 * - * @param req HTTP 请求对象 + * @param _req HTTP 请求对象 * @param res HTTP 响应对象 * @param err 错误对象 * @returns 日志级别 * @private */ - private static customLogLevel(req: any, res: any, err: any) { + private static customLogLevel(_req: any, res: any, err: any) { if (res.statusCode >= 400 && res.statusCode < 500) { return 'warn'; } else if (res.statusCode >= 500 || err) { @@ -255,7 +242,7 @@ export class LoggerConfigFactory { * @private */ private static generateRequestId(): string { - return `req_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; + return `req_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`; } /**