v2.1Introduction
Migrating from v1 to v2
What broke between 1.x and 2.0, the rename table and an upgrade checklist.
Version 2 changes the record shape, the stream API and the way the package is imported. The format-parsing logic is the same: results on identical input match, except for what is listed below.
What changed#
| v1 | v2 | Note |
|---|---|---|
sverlo.parser(opts) | createParser(opts) | New name, same options plus new ones |
parser.parse(line, cb) | parser.parseLine(line) | Callback removed, the result is returned |
rec.time (string) | rec.ts (Date) | A real date object now |
rec.severity ('WARN') | rec.level ('warn') | Lower case, normalised |
rec.message | rec.msg | |
rec.data | rec.fields | Object without a prototype |
sverlo.createStream(opts) | createTransform(opts) | |
require('sverlo') | import { createParser } from 'sverlo' | ESM only |
Behaviour#
- An unrecognised line used to call the callback with an error; now it is skipped by default. Get the old behaviour back with
onError: 'throw'. - Time without a zone was UTC in v1 and is local process time in v2. If you relied on the old behaviour, set
timezone: 'UTC'. - Filters in v1 were predicate functions. In v2 you can write a query as well; functions still work.
Checklist#
- Replace
requirewithimportor a dynamicimport(). - Rename record properties using the table above.
- Set
timezoneexplicitly. - Replace
parse(line, cb)callbacks withparseLine(line). - Check that nothing depends on upper-case levels.
- Upgrade Node.js to version 20 or newer.
Both packages side by side#
For a gradual move, install v1 under another name:
npm install sverlo1@npm:sverlo@1Then import legacy from 'sverlo1' and import { createParser } from 'sverlo' work in one project. The old documentation remains in the v1 archive.