日志模块拆分 category 参数:log.xxx(category, ...args) 输出 timestamp [level] [category]

- log.js 签名改为 log.xxx(category, ...args);头三段为时间戳 [level] [category],后续参数(含 Error/对象)透传 console 走 util.format
- 所有调用点迁移:从 log.info('[msg] xxx') → log.info('msg', 'xxx');server 启动行无前缀,统一归入 startup
- 实测输出:2026-09-05 09:27:12.068 [debug] [sse] task-20260904-012 event: ping
This commit is contained in:
2026-09-05 09:27:23 +08:00
parent 3538526c41
commit 734039d917
12 changed files with 67 additions and 61 deletions
+2 -2
View File
@@ -97,7 +97,7 @@ function createAuth(cfg) {
const secret = (cfg.auth.secret && String(cfg.auth.secret)) || crypto.randomBytes(32).toString('hex');
if (!cfg.auth.secret) {
log.warn('[auth] 未配置 auth.secret,已使用随机密钥:进程重启后所有登录态失效');
log.warn('auth', '未配置 auth.secret,已使用随机密钥:进程重启后所有登录态失效');
}
const ttlMs = Number(cfg.auth.ttl_ms) || DEFAULT_TTL_MS;
const validUsers = new Map(users.map(u => [String(u.user), String(u.password)]));
@@ -174,7 +174,7 @@ function createAuth(cfg) {
// 内存同步:users 与 engine.cfg 是同一对象,Basic 认证实时生效;cookie 登录查 validUsers
users[idx].password = newP;
validUsers.set(me, newP);
log.info('[auth] 用户 ' + me + ' 修改了密码');
log.info('auth', '用户 ' + me + ' 修改了密码');
res.json({ ok: true });
} catch (e) {
res.status(500).json({ error: String(e && e.message || e) });