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.
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#
| Type | Reads | Result |
|---|---|---|
iso | ISO 8601 date and time | Date |
level | trace, debug, info, warn, error, fatal and common synonyms | lower-case string |
int, float | numbers | number |
word | up to the next space | string |
quoted | text in double quotes | string without quotes |
ip | IPv4 or IPv6 | string |
rest | everything to the end of the line | string |
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:
{ts:iso} {level:level} {trace:word?} {msg:rest}2026-10-01T09:14:07Z INFO started parses, and trace stays undefined.
Rules#
restis only allowed at the end of a pattern.- 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.
- 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.