Skip to content
Grant Carthew edited this page Oct 25, 2024 · 6 revisions

perj dataKey Option

The dataKey option enables you to change the JSON key used for the data or object output.

Type: String

Default: data

Valid: Any String

Description:

The dataKey option is used to change the key used in the output JSON for the data or object value. For example, the default dataKey of 'data' will produce an output from the logger of:

{"level": "info", "lvl": 30, "time": 12345, "msg": "something", "data": {...

If you set the dataKey option to 'context' then the output from the logger would look like:

{"level": "info", "lvl": 30, "time": 12345, "msg": "something", "context": {...

Example

This example changes the dataKey from the default of 'data' to 'context':

import Perj from 'perj'
const log = new Perj({ dataKey: 'context' })

log.info('See attached', { foo: 'bar' })

/*

Standard out will be:

{"level":"info","lvl":30,"time":1525643291716,"msg":"See attached","context": { "foo": "bar" }}

*/