From 8325431d4e01d3e7771c06cd34df77e806bea4cd 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: Sat, 17 Feb 2024 15:23:37 +0900 Subject: [PATCH] =?UTF-8?q?fix(backend/logger):=20`context`=E3=81=AE?= =?UTF-8?q?=E5=BC=95=E6=95=B0=E3=82=92=E6=B8=A1=E3=81=99=E3=81=A8logger?= =?UTF-8?q?=E3=81=AB=E8=A8=AD=E5=AE=9A=E3=81=95=E3=82=8C=E3=81=9Fcontext?= =?UTF-8?q?=E3=81=8C=E4=B8=8A=E6=9B=B8=E3=81=8D=E3=81=95=E3=82=8C=E3=81=A6?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=86=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=20(MisskeyIO#459)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/logger.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/logger.ts b/packages/backend/src/logger.ts index 21711e6a78..4cb952b280 100644 --- a/packages/backend/src/logger.ts +++ b/packages/backend/src/logger.ts @@ -13,6 +13,7 @@ import type { KEYWORD } from 'color-convert/conversions.js'; export default class Logger { private readonly domain: string; private logger: pino.Logger; + private context: Record = {}; constructor(domain: string, _color?: KEYWORD, _store = true, parentLogger?: Logger) { if (parentLogger) { @@ -34,7 +35,7 @@ export default class Logger { formatters: { level: (label, number) => ({ severity: label, level: number }), }, - mixin: () => ({ cluster: cluster.isPrimary ? 'primary' : `worker#${cluster.worker!.id}` }), + mixin: () => ({ cluster: cluster.isPrimary ? 'primary' : `worker#${cluster.worker!.id}`, ...this.context }), transport: !envOption.logJson ? { target: 'pino-pretty', options: { @@ -57,7 +58,7 @@ export default class Logger { @bindThis public setContext(context: Record): void { - this.logger = this.logger.child({ context }); + this.context = context; } @bindThis