MCPcopy Index your code
hub / github.com/BlockRunAI/ClawRouter / parseLogFile

Function parseLogFile

src/stats.ts:47–72  ·  view source on GitHub ↗

* Parse a JSONL log file into usage entries. * Handles both old format (without tier/baselineCost) and new format.

(filePath: string)

Source from the content-addressed store, hash-verified

45 * Handles both old format (without tier/baselineCost) and new format.
46 */
47async function parseLogFile(filePath: string): Promise<UsageEntry[]> {
48 try {
49 const content = await readTextFile(filePath);
50 const lines = content.trim().split("\n").filter(Boolean);
51 const entries: UsageEntry[] = [];
52 for (const line of lines) {
53 try {
54 const entry = JSON.parse(line) as Partial<UsageEntry>;
55 entries.push({
56 timestamp: entry.timestamp || new Date().toISOString(),
57 model: entry.model || "unknown",
58 tier: entry.tier || "UNKNOWN",
59 cost: entry.cost || 0,
60 baselineCost: entry.baselineCost || entry.cost || 0,
61 savings: entry.savings || 0,
62 latencyMs: entry.latencyMs || 0,
63 });
64 } catch {
65 // Skip malformed lines, keep valid ones
66 }
67 }
68 return entries;
69 } catch {
70 return [];
71 }
72}
73
74/**
75 * Get list of available log files sorted by date (newest first).

Callers 2

getStatsFunction · 0.85
formatRecentLogsFunction · 0.85

Calls 1

readTextFileFunction · 0.85

Tested by

no test coverage detected