Optional
count: numberNumber of log lines to return (default: 100)
Array of log lines
export function getLogs(count?: number): string[] {
try {
if (fs.existsSync(latestLogPath)) {
const logContent = fs.readFileSync(latestLogPath, "utf-8");
const logLines = logContent
.split("\n")
.filter((line) => line.trim() !== "");
// Return at most 'count' lines from latest.log, or all if count is undefined
return count ? logLines.slice(-count) : logLines;
}
return [];
} catch (error) {
console.error("Error reading logs:", error);
return [
`[${new Date().toLocaleTimeString()}] [ERROR] Error reading logs: ${error}`,
];
}
}
Retrieves log entries from latest.log file only