2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.jsでpino-prettyを使う

Posted at

instrumentationHook は先んじて next.config.mjs で有効にしておく

instrumentation.ts
export const register = async () => {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    /* eslint-disable @typescript-eslint/no-require-imports */
    await require("pino");
    await require("next-logger");
  }
};

本番ではpino-prettyは有効にしない

next-logger.config.js
const pino = require("pino");

module.exports = {
  logger: (defaultConfig) => {
    const opts =
      process.env.NODE_ENV === "production"
        ? {}
        : {
            transport: {
              target: "pino-pretty",
              options: {
                colorized: true,
              },
            },
          };

    return pino({
      ...defaultConfig,
      ...opts,
    });
  },
};
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?