添加日志相关功能

This commit is contained in:
2026-09-02 09:57:04 +08:00
parent 282e73fca4
commit 5ee8fb2806
12 changed files with 53 additions and 26 deletions
+3 -2
View File
@@ -4,6 +4,7 @@
const express = require('express');
const engine = require('../engine');
const { loadConfigFromText, readConfigText, applyEditsToText, writeConfigText } = require('../config');
const log = require('../log');
const router = express.Router();
@@ -61,7 +62,7 @@ router.put('/', wrap((req, res) => {
let next;
try { next = loadConfigFromText(text, cfg.config_path); } catch (e) { return badRequest(res, e); }
writeConfigText(cfg, text);
console.log('[config] ' + (req.user || '-') + ' 整文件保存配置,变更段:' + (diffTop(cfg, next).join(',') || '无'));
log.info('[config] ' + (req.user || '-') + ' 整文件保存配置,变更段:' + (diffTop(cfg, next).join(',') || '无'));
res.json({ ok: true, changed: diffTop(cfg, next), restart_required: true });
}));
@@ -84,7 +85,7 @@ router.patch('/', wrap((req, res) => {
let next;
try { next = loadConfigFromText(nextText, cfg.config_path); } catch (e) { return badRequest(res, e); }
writeConfigText(cfg, nextText);
console.log('[config] ' + (req.user || '-') + ' 修改配置项 ' + pathArr.join('.') + (body.op === 'delete' ? '(删除)' : '') + ',变更段:' + (diffTop(cfg, next).join(',') || '无'));
log.info('[config] ' + (req.user || '-') + ' 修改配置项 ' + pathArr.join('.') + (body.op === 'delete' ? '(删除)' : '') + ',变更段:' + (diffTop(cfg, next).join(',') || '无'));
res.json({ ok: true, changed: diffTop(cfg, next), restart_required: true });
}));