Use pino on server and client side in Next.js project
npm install --save pino next-pino
or
yarn add pino next-pino
Create a next.config.js
in your project
// next.config.js
const withPino = require("next-pino");
module.exports = withPino();
Create a logger file utils/logger/JsonLogger.js
import pino from "pino";
export default pino()({
// usual pino config
});
Then you could use it on another file, for example
import JsonLogger from "utils/logger/JsonLogger.js";
JsonLogger.info("foo bar");
Optionally you can add your custom Next.js configuration as parameter
// next.config.js
const withPino = require("next-pino");
module.exports = withPino({
webpack(config, options) {
return config;
}
});