Skip to content
Sections
LanguageRUEN

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.

ts
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#

FieldDescription
tsThe moment as a Date; null when the format has no time
levelNormalised level; the synonyms warning, err and crit map to the standard ones
msgMessage text; multi-line records contain newlines
fieldsOther extracted values
rawSource text of the line (all lines for a multi-line record)
lineNumber of the first line of the record, counting from one

Rules#

  1. The properties ts, level, msg, fields, raw and line exist on every record. A missing value is null or an empty string, never undefined.
  2. fields is created without a prototype, so a key named __proto__ in a log is an ordinary property and harmless.
  3. Pattern fields of type int and float are always a number; if parsing is impossible the line is dropped with E_NO_MATCH.

Serialising#

js
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.

Updated: