fix(logs): make log storage location safe and configurable
Adds an AppData/Desktop log storage selector with controlled migration of known log files only. Keeps runtime data and credentials in AppData, consolidates desktop rename logs into the chosen directory, and exposes the active log folder through the desktop UI.\n\nFlushes early recovery diagnostics into the runtime log before a location migration, preserves the active trace configuration as valid JSON during moves, and prevents backup imports from failing when the requested log location is unavailable. Adds regression coverage for desktop paths, legacy log migration, secret exclusion, and trace-config replacement.
This commit is contained in:
@@ -4,7 +4,7 @@ import { logTimestamp } from "./log-timestamp";
|
||||
|
||||
type DesktopRenameLevel = "INFO" | "WARN" | "ERROR";
|
||||
|
||||
const FOLDER_NAME = "Downloader-Log";
|
||||
const LEGACY_FOLDER_NAME = "Downloader-Log";
|
||||
|
||||
let logDir: string | null = null;
|
||||
let logFilePath: string | null = null;
|
||||
@@ -58,15 +58,15 @@ function ensureWritable(): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
export function initDesktopRenameLog(desktopDir: string | null | undefined): void {
|
||||
try {
|
||||
const base = String(desktopDir || "").trim();
|
||||
if (!base) {
|
||||
logDir = null;
|
||||
logFilePath = null;
|
||||
return;
|
||||
}
|
||||
logDir = path.join(base, FOLDER_NAME);
|
||||
function initializeRenameLog(directory: string | null | undefined): void {
|
||||
try {
|
||||
const base = String(directory || "").trim();
|
||||
if (!base) {
|
||||
logDir = null;
|
||||
logFilePath = null;
|
||||
return;
|
||||
}
|
||||
logDir = path.resolve(base);
|
||||
logFilePath = path.join(logDir, `rename-session_${fileTimestamp()}.txt`);
|
||||
sessionHeader = `=== Rename-Session gestartet: ${logTimestamp()} ===\n`
|
||||
+ "Diese Datei protokolliert JEDEN Umbenenn-/Verschiebevorgang dieser Programm-Sitzung\n"
|
||||
@@ -77,8 +77,17 @@ export function initDesktopRenameLog(desktopDir: string | null | undefined): voi
|
||||
} catch {
|
||||
logDir = null;
|
||||
logFilePath = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function initDesktopRenameLog(desktopDir: string | null | undefined): void {
|
||||
const base = String(desktopDir || "").trim();
|
||||
initializeRenameLog(base ? path.join(base, LEGACY_FOLDER_NAME) : null);
|
||||
}
|
||||
|
||||
export function initDesktopRenameLogAt(directory: string | null | undefined): void {
|
||||
initializeRenameLog(directory);
|
||||
}
|
||||
|
||||
export function logDesktopRename(level: DesktopRenameLevel, message: string, fields?: Record<string, unknown>): void {
|
||||
if (!ensureWritable() || !logFilePath) {
|
||||
|
||||
Reference in New Issue
Block a user