- Notifications
You must be signed in to change notification settings - Fork13
🌲 Include call site of pino log messages
License
NotificationsYou must be signed in to change notification settings
pinojs/pino-caller
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
pino-caller
is a wrapper forpino which adds the call site of each log message to the log output.This can be useful when developing with large codebases in order to locate the exact point where pino is invoked.
For Pino v4 and below use the v2 line, which can be installed with the@legacy
tag:
npm install pino-caller@legacy
For Pino v5 and above use the v3+ line, which will install using the usual command:
npm install pino-caller
WARNING: THIS IS A DEVELOPMENT TOOL AVOID PRODUCTION USE!
'use strict'constpino=require('pino')()// it will print as usualconstpinoCaller=require('pino-caller')(pino)// it will print also the calling sitepinoCaller.info('info1')pinoCaller.error('error1')pinoCaller.debug('debug1')
'use strict'// dynamically load the plugin if in development environment, output paths relative to __dirnameconstpino=process.env.NODE_ENV==='development' ?require('pino-caller')(require('pino')(),{relativeTo:__dirname}) :require('pino')()pino.info('info1')pino.error('error1')pino.debug('debug1')
You can find also a working example in theexamples
directory and you can run it withnpm run example
- relativeTo - Remove path prefixes from log messages to make them easier to read.
- stackAdjustment - For those who've wrapped pino, make pino-caller move N stackframes up to get a meaningful message.
'use strict'constpino=require('pino')()constpinoCaller=require('pino-caller')(pino,{relativeTo:__dirname,stackAdjustment:1})// People who have wrapped pino like in the contrived example below// will want to use stackAdjustment.// Most people will NOT need this. See issue #90 for details.constlog={info:function(message){pinoCaller.info(message)}}
╭─phra at debian in /home/phra/git/pino-caller (master ✔)╰─λ npm run example> pino-caller@1.0.0 example /home/phra/git/pino-caller> env NODE_ENV=development node examples/index.js{"pid":44837,"hostname":"debian","level":30,"time":1487873713227,"msg":"hello from the module!","caller":"Object.<anonymous> (/home/phra/git/pino-caller/examples/module.js:4:12)","v":1}{"pid":44837,"hostname":"debian","level":30,"time":1487873713230,"msg":"info1","caller":"Object.<anonymous> (index.js:8:12)","v":1}{"pid":44837,"hostname":"debian","level":50,"time":1487873713230,"msg":"error1","caller":"Object.<anonymous> (index.js:9:12)","v":1}
About
🌲 Include call site of pino log messages
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published