优化日志系统
This commit is contained in:
+13
-6
@@ -76,9 +76,10 @@
|
||||
.log-body{flex:1;overflow-y:auto;padding:10px 16px;font-family:'Consolas','Courier New',monospace;font-size:13px;line-height:1.8}
|
||||
.log-s{color:#7ee787}
|
||||
.log-e{color:#f78166}
|
||||
.log-i{color:#58a6ff}
|
||||
.log-w{color:#f0883e}
|
||||
.log-result{background:#1a1f2b;padding:2px 8px;margin:2px 0;border-radius:3px;word-break:break-all}
|
||||
.log-i{color:#58a6ff}
|
||||
.log-w{color:#f0883e}
|
||||
.log-result{background:#1a1f2b;padding:2px 8px;margin:2px 0;border-radius:3px;word-break:break-all}
|
||||
.log-cat{display:inline-block;min-width:34px;text-align:center;margin-right:6px;padding:0 5px;border:1px solid#30363d;border-radius:4px;color:#8b949e;font-size:11px;line-height:1.4}
|
||||
|
||||
/* ========== 右侧滑入提示 ========== */
|
||||
.toast-container{position:fixed;top:20px;right:-420px;z-index:9999;transition:right .4s ease}
|
||||
@@ -632,18 +633,24 @@
|
||||
if (item.level === 'success') type = 's';
|
||||
else if (item.level === 'error') type = 'e';
|
||||
else if (item.level === 'warn') type = 'w';
|
||||
addServerLog(item.message, type);
|
||||
addServerLog(item.message, type, item.category);
|
||||
});
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
// addServerLog 追加一条后端日志,和本地操作日志共用同一个日志区域。
|
||||
function addServerLog(msg, type = 'i') {
|
||||
function addServerLog(msg, type = 'i', category = '') {
|
||||
let el = document.getElementById('logBody');
|
||||
el.innerHTML += `<div class="log-${type}">[后端] ${escHtml(msg)}</div>`;
|
||||
let cat = category ? `<span class="log-cat">${escHtml(category)}</span>` : '';
|
||||
el.innerHTML += `<div class="log-${type}">[后端] ${cat}${escHtml(cleanServerLogMessage(msg))}</div>`;
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
|
||||
// cleanServerLogMessage 去掉后端结构化日志前缀,分类由单独标签展示。
|
||||
function cleanServerLogMessage(msg) {
|
||||
return String(msg ?? '').replace(/\[[^\]]+\]\[(info|success|warn|error)\]\s*/i, '');
|
||||
}
|
||||
|
||||
|
||||
// buildAP 根据已勾选账号和账号绑定商品,生成后端需要的账号到商品 ID 映射。
|
||||
function buildAP() {
|
||||
|
||||
Reference in New Issue
Block a user