fix(logging): pino-prettyの使用時のメモリ使用量の問題を修正 (MisskeyIO#506)

This commit is contained in:
まっちゃとーにゅ 2024-03-06 03:51:13 +09:00 committed by GitHub
parent 1c3742b711
commit 8169fe4e73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 13 deletions

View File

@ -5,10 +5,22 @@
import cluster from 'node:cluster'; import cluster from 'node:cluster';
import { pino } from 'pino'; import { pino } from 'pino';
import pinoPretty from 'pino-pretty';
import { bindThis } from '@/decorators.js'; import { bindThis } from '@/decorators.js';
import { envOption } from './env.js'; import { envOption } from './env.js';
import type { KEYWORD } from 'color-convert/conversions.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 // eslint-disable-next-line import/no-default-export
export default class Logger { export default class Logger {
private readonly domain: string; private readonly domain: string;
@ -36,19 +48,7 @@ export default class Logger {
level: (label, number) => ({ severity: label, level: number }), level: (label, number) => ({ severity: label, level: number }),
}, },
mixin: () => ({ cluster: cluster.isPrimary ? 'primary' : `worker#${cluster.worker!.id}`, ...this.context }), mixin: () => ({ cluster: cluster.isPrimary ? 'primary' : `worker#${cluster.worker!.id}`, ...this.context }),
transport: !envOption.logJson ? { }, !envOption.logJson ? pinoPrettyStream : undefined);
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,
});
} }
@bindThis @bindThis