From 8169fe4e73a73140bf67e8b0a0ad888e6c31f487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Wed, 6 Mar 2024 03:51:13 +0900 Subject: [PATCH] =?UTF-8?q?fix(logging):=20pino-pretty=E3=81=AE=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=99=82=E3=81=AE=E3=83=A1=E3=83=A2=E3=83=AA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=87=8F=E3=81=AE=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=20(MisskeyIO#506)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/logger.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/backend/src/logger.ts b/packages/backend/src/logger.ts index 4cb952b280..08f18b066e 100644 --- a/packages/backend/src/logger.ts +++ b/packages/backend/src/logger.ts @@ -5,10 +5,22 @@ import cluster from 'node:cluster'; import { pino } from 'pino'; +import pinoPretty from 'pino-pretty'; import { bindThis } from '@/decorators.js'; import { envOption } from './env.js'; import type { KEYWORD } from 'color-convert/conversions.js'; +// @ts-expect-error it gives error if we use pinoPretty.PinoPretty instead of pinoPretty. +const pinoPrettyStream = pinoPretty({ + levelFirst: false, + levelKey: 'level', + timestampKey: 'time', + messageKey: 'message', + errorLikeObjectKeys: ['e', 'err', 'error'], + ignore: 'severity,pid,hostname,cluster,important', + messageFormat: '@{cluster} | {message}', +}); + // eslint-disable-next-line import/no-default-export export default class Logger { private readonly domain: string; @@ -36,19 +48,7 @@ export default class Logger { level: (label, number) => ({ severity: label, level: number }), }, mixin: () => ({ cluster: cluster.isPrimary ? 'primary' : `worker#${cluster.worker!.id}`, ...this.context }), - transport: !envOption.logJson ? { - target: 'pino-pretty', - options: { - levelFirst: false, - levelKey: 'level', - timestampKey: 'time', - messageKey: 'message', - errorLikeObjectKeys: ['e', 'err', 'error'], - ignore: 'severity,pid,hostname,cluster,important', - messageFormat: '@{cluster} | {message}', - }, - } : undefined, - }); + }, !envOption.logJson ? pinoPrettyStream : undefined); } @bindThis