-
Notifications
You must be signed in to change notification settings - Fork 1
dataKey
Grant Carthew edited this page Oct 25, 2024
·
6 revisions
The dataKey
option enables you to change the JSON key used for the data or object output.
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": {...
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" }}
*/