-
Notifications
You must be signed in to change notification settings - Fork 1
separatorString
Grant Carthew edited this page Oct 25, 2024
·
8 revisions
The separatorString
option allows you to customize the string used to separate child top level properties.
If you create a top level property key
with a value of a string, then use the same key
when you create a child logger, the separatorString
is inserted between the parent and child string values.
For this to work you must meet these requirements:
- Create a top level property when creating either a root or child logger.
- Remember the
key
name you used. - Ensure the
key
contains a string value. - Use the same
key
name when you create child loggers from the parent. - Ensure the
key
on the child contains a string.
Here is an example of a value you would get from a child logger if you changed the separatorString
from the default of :
to >
:
keyName: 'parent > child1 > child2 > child3 > child4'
and so on.
This example shows the default separatorString
being used on a top level key called 'component':
import Perj from 'perj';
const parent = new Perj({ component: 'app' })
parent.info('parent')
// {"level":"info","lvl":50,"component":"app","time":1525643291716,"msg":"parent","data":""}
const firstChild = parent.child({ component: 'route' })
firstChild.info('child1')
// {"level":"info","lvl":50,"component":"app:route","time":1525643291716,"msg":"child1","data":""}
const secondChild = firstChild.child({ component: 'auth' })
secondChild.info('child2')
// {"level":"info","lvl":50,"component":"app:route:auth","time":1525643291716,"msg":"child2","data":""}
This example shows a custom separatorString
being used on a top level key called 'module':
import Perj from 'perj';
const parent = new Perj({ separatorString: ' > ', module: 'app' })
parent.info('parent')
// {"level":"info","lvl":50,"module":"app","time":1525643291716,"msg":"parent","data":""}
const firstChild = parent.child({ module: 'route' })
firstChild.info('child1')
// {"level":"info","lvl":50,"module":"app > route","time":1525643291716,"msg":"child1","data":""}
const secondChild = firstChild.child({ module: 'auth' })
secondChild.info('child2')
// {"level":"info","lvl":50,"module":"app > route > auth","time":1525643291716,"msg":"child2","data":""}