analyze-logs
v0.1.4
Published
Builds a tree from start/end log entries and flattens it for display.
Readme
analyze-logs
Builds a hierarchical tree from start/end log entries and flattens it into a table.
Install
npm install analyze-logsUsage (API)
import { buildTree, flattenTree, parseDateTime, type LogEntry } from 'analyze-logs';
const logs: LogEntry[] = [
{ dateTime: '2024-01-01:12-00-00-000', name: 'taskA', value: 'start' },
{ dateTime: '2024-01-01:12-00-01-000', name: 'step1', value: 'work' },
{ dateTime: '2024-01-01:12-00-02-000', name: 'taskA', value: 'end' },
];
const tree = buildTree(logs);
const rows = flattenTree(tree);
console.table(rows);CLI
npx analyze-logs path/to/logs.jsonIf no path is provided, it looks for logs.json in the current directory.
JSON format
[
{ "dateTime": "YYYY-MM-DD:HH-mm-ss-SSS", "name": "task", "value": "start|end|error|other" }
]startopens a new nested node.endcloses the most recent node with the samename.errorcloses the most recent node with the samename.- Other values become leaf events with zero duration.
License
MIT
