Include desktop app logs in diagnostics (#1914)
* 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
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import log from "electron-log/main";
|
||||
import { tailFile } from "./tail-file.js";
|
||||
|
||||
const APP_LOG_TAIL_LINES = 100;
|
||||
|
||||
export interface DesktopAppLogs {
|
||||
logPath: string;
|
||||
contents: string;
|
||||
}
|
||||
|
||||
export function getDesktopAppLogs(): DesktopAppLogs {
|
||||
const logPath = log.transports.file.getFile().path;
|
||||
return {
|
||||
logPath,
|
||||
contents: tailFile(logPath, APP_LOG_TAIL_LINES, { throwOnReadError: true }),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { tailFile } from "./tail-file";
|
||||
|
||||
let testDir = "";
|
||||
|
||||
describe("tailFile", () => {
|
||||
beforeEach(() => {
|
||||
testDir = mkdtempSync(path.join(tmpdir(), "paseo-tail-file-"));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
rmSync(testDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("returns the requested tail lines", () => {
|
||||
const filePath = path.join(testDir, "main.log");
|
||||
writeFileSync(filePath, "one\ntwo\nthree\n");
|
||||
|
||||
expect(tailFile(filePath, 2)).toBe("two\nthree");
|
||||
});
|
||||
|
||||
it("keeps missing files empty", () => {
|
||||
expect(tailFile(path.join(testDir, "missing.log"), 2)).toBe("");
|
||||
expect(tailFile(path.join(testDir, "missing.log"), 2, { throwOnReadError: true })).toBe("");
|
||||
});
|
||||
|
||||
it("can propagate read failures", () => {
|
||||
expect(() => tailFile(testDir, 2, { throwOnReadError: true })).toThrow();
|
||||
expect(tailFile(testDir, 2)).toBe("");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
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";
|
||||
}
|
||||
Reference in New Issue
Block a user