fix(backend/logger): context
の引数を渡すとloggerに設定されたcontextが上書きされてしまう問題を修正 (MisskeyIO#459)
This commit is contained in:
parent
2573df5c84
commit
8325431d4e
|
@ -13,6 +13,7 @@ import type { KEYWORD } from 'color-convert/conversions.js';
|
||||||
export default class Logger {
|
export default class Logger {
|
||||||
private readonly domain: string;
|
private readonly domain: string;
|
||||||
private logger: pino.Logger;
|
private logger: pino.Logger;
|
||||||
|
private context: Record<string, any> = {};
|
||||||
|
|
||||||
constructor(domain: string, _color?: KEYWORD, _store = true, parentLogger?: Logger) {
|
constructor(domain: string, _color?: KEYWORD, _store = true, parentLogger?: Logger) {
|
||||||
if (parentLogger) {
|
if (parentLogger) {
|
||||||
|
@ -34,7 +35,7 @@ export default class Logger {
|
||||||
formatters: {
|
formatters: {
|
||||||
level: (label, number) => ({ severity: label, level: number }),
|
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 ? {
|
transport: !envOption.logJson ? {
|
||||||
target: 'pino-pretty',
|
target: 'pino-pretty',
|
||||||
options: {
|
options: {
|
||||||
|
@ -57,7 +58,7 @@ export default class Logger {
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public setContext(context: Record<string, any>): void {
|
public setContext(context: Record<string, any>): void {
|
||||||
this.logger = this.logger.child({ context });
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
Loading…
Reference in a new issue