* fix(diagnostics): include desktop app logs Settings diagnostics now collect the Electron main-process log separately from daemon.log so desktop startup and environment-probe failures are included in app reports. * refactor(desktop): share log tail reader * fix(diagnostics): surface desktop app log read errors * refactor(diagnostics): tighten desktop report API
22 lines
622 B
TypeScript
22 lines
622 B
TypeScript
import { readFileSync } from "node:fs";
|
|
|
|
interface TailFileOptions {
|
|
throwOnReadError?: boolean;
|
|
}
|
|
|
|
export function tailFile(filePath: string, lines = 50, options: TailFileOptions = {}): string {
|
|
try {
|
|
const content = readFileSync(filePath, "utf-8");
|
|
return content.split("\n").filter(Boolean).slice(-lines).join("\n");
|
|
} catch (error) {
|
|
if (options.throwOnReadError && !isMissingFileError(error)) {
|
|
throw error;
|
|
}
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function isMissingFileError(error: unknown): boolean {
|
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
}
|