feat(webui): add trace warning and full export
Require explicit acknowledgement whenever operators enable TRACE and keep its active state visible until they restore normal logging.\n\nAdd an authenticated browser download for the complete retained logging snapshot, including runtime context and clear privacy guidance, while preserving the existing filtered-view export and memory-only TRACE boundary.\n\nCover the transition, snapshot, formatting, download, and client contracts with focused regression tests.
This commit is contained in:
12 files changed
+423
-11
No files matched your search
@@ -143,6 +143,21 @@ class HttpApiClient implements ApiClient {
|
||||
return data.list ?? [];
|
||||
},
|
||||
stream: (options) => this.openLogStream(options),
|
||||
exportTrace: async () => {
|
||||
const res = await this.request('/api/logs/export/trace');
|
||||
if (!res.ok) {
|
||||
const payload = await readJson<ErrorPayload>(res);
|
||||
throw new ApiError(
|
||||
res.status,
|
||||
extractErrorMessage(payload, res.statusText || '导出失败'),
|
||||
payload.code,
|
||||
);
|
||||
}
|
||||
const disposition = res.headers.get('Content-Disposition') ?? '';
|
||||
const filename = disposition.match(/filename="([^"]+)"/)?.[1]
|
||||
?? 'snowluma-trace.log';
|
||||
return { text: await res.text(), filename };
|
||||
},
|
||||
getLevel: () => this.getJson<{ level: LogLevel; levels: LogLevel[] }>(`/api/logs/level`),
|
||||
setLevel: (level) =>
|
||||
this.postJson<{ level: LogLevel; levels: LogLevel[] }>(`/api/logs/level`, { level }),
|
||||
|
||||
@@ -249,6 +249,8 @@ export interface ApiClient {
|
||||
list(limit?: number): Promise<LogEntry[]>;
|
||||
/** Subscribe to the SSE log stream. Returns a disposer. */
|
||||
stream(options: LogsStreamOptions): () => void;
|
||||
/** Download the complete server-side snapshot of retained normal and TRACE records. */
|
||||
exportTrace(): Promise<{ text: string; filename: string }>;
|
||||
/** Current console / subscriber level. File logging level is set via
|
||||
* SNOWLUMA_LOG_FILE_LEVEL (default: debug), independent of this method. */
|
||||
getLevel(): Promise<{ level: LogLevel; levels: LogLevel[] }>;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { LogLevel } from '@/types';
|
||||
|
||||
export const TRACE_CONFIRMATION_WARNINGS = [
|
||||
'TRACE 会产生非常大量的数据。',
|
||||
'TRACE 可能包含未经脱敏的隐私数据和凭据。',
|
||||
'TRACE 不适合长时间开启。',
|
||||
'TRACE 仅用于小规模问题复现和 bug 反馈。',
|
||||
] as const;
|
||||
|
||||
interface SelectServerLogLevelOptions {
|
||||
currentLevel: LogLevel | null;
|
||||
nextLevel: LogLevel;
|
||||
applyLevel: (level: LogLevel) => void;
|
||||
requestTraceConfirmation: () => void;
|
||||
}
|
||||
|
||||
export function selectServerLogLevel({
|
||||
currentLevel,
|
||||
nextLevel,
|
||||
applyLevel,
|
||||
requestTraceConfirmation,
|
||||
}: SelectServerLogLevelOptions): void {
|
||||
if (currentLevel === null || currentLevel === nextLevel) return;
|
||||
if (currentLevel !== 'trace' && nextLevel === 'trace') {
|
||||
requestTraceConfirmation();
|
||||
return;
|
||||
}
|
||||
applyLevel(nextLevel);
|
||||
}
|
||||
Reference in new issue
Block a user