1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Next.js】Pinoを使用してログを取る方法

Posted at

Pinoをインストール

yarn add pino

Pinoの設定ファイルを作成

lib/pino/logger.ts
import pino from 'pino'

const logLevel = process.env.PINO_LOG_LEVEL ?? 'info'

export const logger = pino({
  level: logLevel,  // 出力するログレベルを設定
  timestamp: pino.stdTimeFunctions.isoTime,  // timestampの形式を変更
  // ログレベルを数値から'error'のような文字列に変更
  formatters: {
    level: (label: string) => {
      return {
        level: label,
      };
    },
  },
  // ブラウザで使用するための設定
  browser: {
    asObject: true,
    serialize: true,
  },
})

ログを出力する

import { logger } from '@/lib/pino/logger'

logger.error('TEST')
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?