Add log4js fileSync logger module and formatError helper
This commit is contained in:
11
src/server/log-format.ts
Normal file
11
src/server/log-format.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 把任意错误/值格式化为带堆栈的字符串,用于日志记录。
|
||||
* - Error:优先 stack,缺则 message
|
||||
* - null/undefined:'Unknown error'
|
||||
* - 其它:String(value)
|
||||
*/
|
||||
export function formatError(err: unknown): string {
|
||||
if (err instanceof Error) return err.stack || err.message;
|
||||
if (err === null || err === undefined) return "Unknown error";
|
||||
return String(err);
|
||||
}
|
||||
Reference in New Issue
Block a user