1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-11 21:28:14 +09:00

fix(backend/logger): contextの引数を渡すとloggerに設定されたcontextが上書きされてしまう問題を修正 (MisskeyIO#459)

This commit is contained in:
まっちゃとーにゅ 2024-02-17 15:23:37 +09:00 committed by GitHub
parent 2573df5c84
commit 8325431d4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<string, any> = {};
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<string, any>): void {
this.logger = this.logger.child({ context });
this.context = context;
}
@bindThis