Skip to content
Sections
LanguageRUEN

v2.1Guide

Patterns for custom formats

How to describe an arbitrary log line with a pattern of typed fields.

A pattern is a string in which text is matched literally and {name:type} extracts a field. It compiles to a finite state machine, not a regular expression, so catastrophic backtracking on bad input cannot happen.

js
const parser = createParser({
  pattern: '{ts:iso} {level:level} {service:word}: {msg:rest}'
});
parser.parseLine('2026-10-01T09:14:07Z ERROR db: connection reset');
// { ts: Date, level: 'error', fields: { service: 'db' }, msg: 'connection reset' }

Field types#

TypeReadsResult
isoISO 8601 date and timeDate
leveltrace, debug, info, warn, error, fatal and common synonymslower-case string
int, floatnumbersnumber
wordup to the next spacestring
quotedtext in double quotesstring without quotes
ipIPv4 or IPv6string
resteverything to the end of the linestring

Fields named ts, level and msg land in the properties of the same name; the others go to rec.fields.

Optional parts#

A ? after the type makes the field optional together with the space before it:

text
{ts:iso} {level:level} {trace:word?} {msg:rest}

2026-10-01T09:14:07Z INFO started parses, and trace stays undefined.

Rules#

  1. rest is only allowed at the end of a pattern.
  2. Two adjacent fields without a separator are rejected, because it is unclear where the first one ends. Sverlo reports it when the parser is created.
  3. A literal { is written {{.

Check a pattern

Run a dozen real lines through sverlo parse --pattern '...' --limit 10 and look at parser.errors. A pattern that swallows everything into rest usually hides a mistake in the format.

Next: filtering the records, see the query language.

Updated: