feat(log): memory-only trace level + request correlation + chokepoint tracing
Debugging from user-supplied logs was impossible: a successful action left one terse, over-summarized debug line and nothing about what it sent QQ or what QQ returned. Add full-chain tracing that stays off disk so it scales to hundreds of groups. common: - New `trace` level (below debug). Never written to file — it lives only in an in-memory ring + the WebUI stream, so the high-volume full chain costs no disk. `emit` early-returns for trace before format/render (and before any lazy producer) when trace isn't active → ~free at the default level. - Dedicated O(1) circular ring for trace (default 5000, SNOWLUMA_TRACE_BUFFER), separate from the normal 1000-entry buffer (also switched off array .shift); getRecentLogs merges both by id. - request-context.ts: AsyncLocalStorage request id. The logger auto-stamps `[req#N]` on every line in a request's async chain — across packages, zero signature threading — and records it on the entry. - log-summary.renderParamsVerbose: deep render of params (nested structure, per-string cap, total budget, token/password/secret redaction). chokepoints (auto-cover every action without touching 100+ handlers): - onebot api-handler: wrap each action in a request id (only when trace is live); trace the full params on entry and status+elapsed on exit; the terse debug breadcrumb still persists to file, failures still warn. - core bridge.sendRawPacket: trace on success (cmd, sizes, elapsed); warn on errorCode!=0 / no response (cmd, code, message) so disk keeps real problems. - protocol highway: fold the bare console.log lines into the logger (trace). webui: trace as the lowest filterable level; render the `[req#N]` tag and let search match it. Server needs no change — LOG_LEVELS, getRecentLogs and the SSE stream carry it through.
This commit is contained in:
9 files changed
+375
-30
No files matched your search
@@ -12,6 +12,7 @@ import type { LogEntry, LogLevel } from '@/types';
|
||||
import { useApi } from '@/lib/api';
|
||||
|
||||
const levelClass: Record<LogLevel, string> = {
|
||||
trace: 'text-muted-foreground/60',
|
||||
debug: 'text-muted-foreground',
|
||||
info: 'text-primary',
|
||||
success: 'text-success',
|
||||
@@ -19,7 +20,7 @@ const levelClass: Record<LogLevel, string> = {
|
||||
error: 'text-destructive',
|
||||
};
|
||||
|
||||
const LEVELS: LogLevel[] = ['debug', 'info', 'success', 'warn', 'error'];
|
||||
const LEVELS: LogLevel[] = ['trace', 'debug', 'info', 'success', 'warn', 'error'];
|
||||
|
||||
/** Show a locale time when the backend sends an ISO timestamp (it does);
|
||||
* fall back to the raw string otherwise so we never render "Invalid Date". */
|
||||
@@ -98,7 +99,8 @@ export function LogsPage() {
|
||||
return (
|
||||
l.message.toLowerCase().includes(f) ||
|
||||
l.scope.toLowerCase().includes(f) ||
|
||||
l.level.toLowerCase().includes(f)
|
||||
l.level.toLowerCase().includes(f) ||
|
||||
(l.req !== undefined && String(l.req).includes(f))
|
||||
);
|
||||
});
|
||||
}, [logs, filter, enabledLevels]);
|
||||
@@ -223,6 +225,11 @@ export function LogsPage() {
|
||||
{log.level.toUpperCase()}
|
||||
</span>
|
||||
<span className="min-w-0 truncate text-muted-foreground sm:w-28">[{log.scope}]</span>
|
||||
{log.req !== undefined && (
|
||||
<span className="shrink-0 rounded bg-primary/10 px-1 text-[10px] text-primary tabular-nums" title="请求关联号">
|
||||
#{log.req}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="min-w-0 whitespace-pre-wrap break-all">{log.message}</span>
|
||||
</motion.div>
|
||||
|
||||
Reference in new issue
Block a user