fix:修复Pino日志配置的Worker线程序列化问题

- 移除customPrettifiers中的箭头函数以避免DataCloneError
- 修复未使用参数的TypeScript警告
- 替换已弃用的substr方法为substring
This commit is contained in:
moyin
2025-12-17 11:03:03 +08:00
parent 2ce05931dd
commit 8fbfc0202b

View File

@@ -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<number, string> = {
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)}`;
}
/**