v2.1API
Record
The shape of the record object returned by parseLine and stream, and the rules for missing fields.
Every successfully parsed line becomes a plain object. It is not tied to the parser, so it can be serialised and passed on.
interface Record {
ts: Date | null;
level: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | null;
msg: string;
fields: { [name: string]: string | number | boolean | null };
raw: string;
line: number;
}Fields#
| Field | Description |
|---|---|
ts | The moment as a Date; null when the format has no time |
level | Normalised level; the synonyms warning, err and crit map to the standard ones |
msg | Message text; multi-line records contain newlines |
fields | Other extracted values |
raw | Source text of the line (all lines for a multi-line record) |
line | Number of the first line of the record, counting from one |
Rules#
- The properties
ts,level,msg,fields,rawandlineexist on every record. A missing value isnullor an empty string, neverundefined. fieldsis created without a prototype, so a key named__proto__in a log is an ordinary property and harmless.- Pattern fields of type
intandfloatare always anumber; if parsing is impossible the line is dropped withE_NO_MATCH.
Serialising#
console.log(JSON.stringify(rec));
// {"ts":"2026-10-01T09:14:07.000Z","level":"error","msg":"connection reset","fields":{"attempt":3},"raw":"...","line":1}Date turns into an ISO 8601 string in the standard way. To avoid storing a duplicate of the text, drop raw first: const { raw, ...slim } = rec.