node-bunyan
node-bunyan copied to clipboard
Added support for Request ID generators
When processing HTTP requests, it's a good practice to specify a unique request ID value for each log entry. This way, multiple log entries could be grouped together according to the specified request ID, which dramatically helps in debugging/analysing requests processing.
This PR allows to specify custom request ID generation function for logger instances. Which opens a path for easy cls-rtracer
integration. Please see the updated README for more details and examples.
This should be considered a non-breaking minor release.
- added support for Request ID generators
- introduced optional
req_id
property that can be passed to the logger constructor - added tests
- updated README
- updated .gitignore file to exclude IDEA files
- arranged AUTHORS alphabetically
- fixed "engines" property of the package manifest
- added myself as an author
So I'm not sure regarding the maintenance status of this project, I've created and published a forked version of the library, so it could be used straight away if someone would want to.
Hello @trentm, could you look into this, please?
Feels like it should be separate to a logger, and bound to .child
Any updates on this?
For anyone who wants to use something similar, you can take advantage of the get
accessor property.
const logger = bunyan.createLogger({ ...options })
Object.defineProperty(log.fields, 'traceId', {
enumable: true,
get: function () {
return 'some-id' // e.g., you can retrieve it from AsyncLocalStorage
}
})