forked from datawhale/whale-town-end
fix:修复Pino日志配置的Worker线程序列化问题
- 移除customPrettifiers中的箭头函数以避免DataCloneError - 修复未使用参数的TypeScript警告 - 替换已弃用的substr方法为substring
This commit is contained in:
@@ -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}`;
|
return `${req.method} ${req.url} failed: ${err.message}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -152,20 +152,7 @@ export class LoggerConfigFactory {
|
|||||||
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss',
|
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss',
|
||||||
ignore: 'pid,hostname',
|
ignore: 'pid,hostname',
|
||||||
messageFormat: '{app} [{level}] {msg}',
|
messageFormat: '{app} [{level}] {msg}',
|
||||||
customPrettifiers: {
|
// 移除 customPrettifiers 以避免 Worker 线程序列化问题
|
||||||
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}`;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
level: logLevel,
|
level: logLevel,
|
||||||
},
|
},
|
||||||
@@ -231,13 +218,13 @@ export class LoggerConfigFactory {
|
|||||||
/**
|
/**
|
||||||
* 自定义日志级别判断
|
* 自定义日志级别判断
|
||||||
*
|
*
|
||||||
* @param req HTTP 请求对象
|
* @param _req HTTP 请求对象
|
||||||
* @param res HTTP 响应对象
|
* @param res HTTP 响应对象
|
||||||
* @param err 错误对象
|
* @param err 错误对象
|
||||||
* @returns 日志级别
|
* @returns 日志级别
|
||||||
* @private
|
* @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) {
|
if (res.statusCode >= 400 && res.statusCode < 500) {
|
||||||
return 'warn';
|
return 'warn';
|
||||||
} else if (res.statusCode >= 500 || err) {
|
} else if (res.statusCode >= 500 || err) {
|
||||||
@@ -255,7 +242,7 @@ export class LoggerConfigFactory {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private static generateRequestId(): string {
|
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)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user