Add log4js fileSync logger module and formatError helper

This commit is contained in:
Misaka_Company
2026-06-24 13:35:10 +08:00
parent e495a9b142
commit 2a5f5763b4
5 changed files with 133 additions and 1 deletions

11
src/server/log-format.ts Normal file
View 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);
}