MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / addLog

Function addLog

static/js/app.js:2120–2156  ·  view source on GitHub ↗
(type, message)

Source from the content-addressed store, hash-verified

2118
2119// 添加日志
2120function addLog(type, message) {
2121 // 日志去重:使用消息内容的 hash 作为键
2122 const logKey = `${type}:${message}`;
2123 if (displayedLogs.has(logKey)) {
2124 return; // 已经显示过,跳过
2125 }
2126 displayedLogs.add(logKey);
2127
2128 // 限制去重集合大小,避免内存泄漏
2129 if (displayedLogs.size > 1000) {
2130 // 清空一半的记录
2131 const keys = Array.from(displayedLogs);
2132 keys.slice(0, 500).forEach(k => displayedLogs.delete(k));
2133 }
2134
2135 const line = document.createElement('div');
2136 line.className = `log-line ${type}`;
2137
2138 // 添加时间戳
2139 const timestamp = new Date().toLocaleTimeString('zh-CN', {
2140 hour: '2-digit',
2141 minute: '2-digit',
2142 second: '2-digit'
2143 });
2144
2145 line.innerHTML = `<span class="timestamp">[${timestamp}]</span>${escapeHtml(message)}`;
2146 elements.consoleLog.appendChild(line);
2147
2148 // 自动滚动到底部
2149 elements.consoleLog.scrollTop = elements.consoleLog.scrollHeight;
2150
2151 // 限制日志行数
2152 const lines = elements.consoleLog.querySelectorAll('.log-line');
2153 if (lines.length > 500) {
2154 lines[0].remove();
2155 }
2156}
2157
2158// 获取日志类型
2159function getLogType(log) {

Callers 15

loadAvailableServicesFunction · 0.85
handleServiceChangeFunction · 0.85
handleSingleRegistrationFunction · 0.85
connectWebSocketFunction · 0.85
handleBatchRegistrationFunction · 0.85
handleCancelTaskFunction · 0.85
startLogPollingFunction · 0.85
startBatchPollingFunction · 0.85

Calls 2

escapeHtmlFunction · 0.70
deleteMethod · 0.45

Tested by

no test coverage detected