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

View File

@ -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