server-base-log
Version:
server base log wrapper using pino
56 lines (36 loc) • 1.42 kB
Markdown
# server base pino logger
simple wrapper for [pino](https://npm.im/pino) used by [server-base](https://npm.im/server-base)
[](https://github.com/feross/standard)
[](https://github.com/JamesKyburz/server-base/actions/workflows/main.yml)
[](https://npmjs.org/package/server-base-log)
# usage
```javascript
const log = require('server-base-log')(__filename, { optional pino options })
log.info('ok')
```
`info, fatal, debug, error, trace and warn` are bound to correct t.equal for convenience.
# log options
All options are passed to `pino`
`opt.pretty` options are passed to `pino.pretty` constructor
default log options are
```
safe: true,
serializers: {
req: pino.stdSerializers.req,
res: pino.stdSerializers.res,
q: pino.stdSerializers.req,
r: pino.stdSerializers.res
}
````
# http request logging
Both `log.info({ q, r })` and `log.info({ req, res })` work.
# env
setting `process.env.LOG_PRETTY` uses `pino.pretty`
setting `process.env.LOG_LEVEL` overrides the default log level which is `debug`
# install
With [npm](https://npmjs.org) do:
```
npm install server-base-log
```
# license
[Apache License, Version 2.0](LICENSE)