misskey/packages/backend/src/core/LoggerService.ts

37 lines
908 B
TypeScript
Raw Normal View History

2022-09-18 14:07:41 +00:00
import { Inject, Injectable } from '@nestjs/common';
import * as SyslogPro from 'syslog-pro';
import { DI } from '@/di-symbols.js';
2022-09-20 20:33:11 +00:00
import type { Config } from '@/config.js';
2022-09-18 14:07:41 +00:00
import Logger from '@/logger.js';
import { bindThis } from '@/decorators.js';
import type { KEYWORD } from 'color-convert/conversions';
2022-09-18 14:07:41 +00:00
@Injectable()
export class LoggerService {
2022-09-18 18:11:50 +00:00
private syslogClient;
2022-09-18 14:07:41 +00:00
constructor(
@Inject(DI.config)
private config: Config,
) {
if (this.config.syslog) {
2022-09-18 18:11:50 +00:00
this.syslogClient = new SyslogPro.RFC5424({
applicationName: 'Misskey',
2022-09-18 14:07:41 +00:00
timestamp: true,
includeStructuredData: true,
2022-09-18 14:07:41 +00:00
color: true,
extendedColor: true,
server: {
target: config.syslog.host,
port: config.syslog.port,
},
});
}
}
@bindThis
public getLogger(domain: string, color?: KEYWORD | undefined, store?: boolean) {
2022-09-18 18:11:50 +00:00
return new Logger(domain, color, store, this.syslogClient);
2022-09-18 14:07:41 +00:00
}
}