/next-pino

Use pino on server and client side in Next.js project

Primary LanguageJavaScriptMIT LicenseMIT

Next.js + Pino

Use pino on server and client side in Next.js project

Installation

npm install --save pino next-pino

or

yarn add pino next-pino

Usage

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");

Configuring Next.js

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;
  }
});