Skip to content

Commit

Permalink
Add README on providing a custom Pino instance
Browse files Browse the repository at this point in the history
  • Loading branch information
atkinchris committed Oct 20, 2021
1 parent aabc446 commit 9015cd3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ The following presets are supported:
- `next-logger/presets/all` - this includes all the patches this library supports. Using the library without a preset specified will use this preset.
- `next-logger/presets/next-only` - this only includes patches specifically for the Next.js logger object.

### Custom Logger

By default, this library uses an instance of Pino with a modified [`logMethod`](https://getpino.io/#/docs/api?id=logmethod), to give reasonable out-the-box behaviour for JSON logging. If you need logs in a different format, for example to change the message field or transform logged objects, you can provide your own instance of Pino to the library.

This is done by creating a `next-logger.config.js` file in the root of your project. The file should be a CommonJS module, and your custom Pino instance should be exported in a field called `logger`. For example:

```js
// next-logger.config.js
const pino = require('pino')

const logger = pino({ messageKey: 'message', mixin: () => ({ name: 'custom-pino-instance' }) })

module.exports = {
logger,
}
```

## Breaking Changes on >=1.0.0

This package name, `next-logger` has been inherited from [@frank47](https://github.com/franky47), who had deprecated their published logging middleware for Next.js. The original package and this one aim to solve similar problems for JSON logging in Next.js. However, the implementation and usage of this solution is significantly different from the original, which was published up to `v0.4.0`. To minimise unexpected issues for previous users of the original `next-logger`, the new package begins at major `v1.0.0`.

0 comments on commit 9015cd3

Please sign in to comment.