forked from FoundKeyGang/FoundKey
Fix type errors in logger service
This commit is contained in:
parent
957a69779a
commit
79c71bf22a
1 changed files with 7 additions and 7 deletions
|
@ -6,9 +6,10 @@ import * as SyslogPro from 'syslog-pro';
|
|||
import config from '@/config/index.js';
|
||||
import { envOption } from '@/env.js';
|
||||
|
||||
type KeywordColor = Parameters<typeof convertColor.keyword.rgb>[0];
|
||||
type Domain = {
|
||||
name: string;
|
||||
color?: string;
|
||||
color?: KeywordColor;
|
||||
};
|
||||
|
||||
type Level = 'error' | 'success' | 'warning' | 'debug' | 'info';
|
||||
|
@ -17,9 +18,9 @@ export default class Logger {
|
|||
private domain: Domain;
|
||||
private parentLogger: Logger | null = null;
|
||||
private store: boolean;
|
||||
private syslogClient: any | null = null;
|
||||
private syslogClient: SyslogPro.RFC5424 | null = null;
|
||||
|
||||
constructor(domain: string, color?: string, store = true) {
|
||||
constructor(domain: string, color?: KeywordColor, store = true) {
|
||||
this.domain = {
|
||||
name: domain,
|
||||
color,
|
||||
|
@ -41,7 +42,7 @@ export default class Logger {
|
|||
}
|
||||
}
|
||||
|
||||
public createSubLogger(domain: string, color?: string, store = true): Logger {
|
||||
public createSubLogger(domain: string, color?: KeywordColor, store = true): Logger {
|
||||
const logger = new Logger(domain, color, store);
|
||||
logger.parentLogger = this;
|
||||
return logger;
|
||||
|
@ -57,7 +58,7 @@ export default class Logger {
|
|||
}
|
||||
|
||||
const time = dateFormat(new Date(), 'HH:mm:ss');
|
||||
const worker = cluster.isPrimary ? '*' : cluster.worker.id;
|
||||
const worker = cluster.isPrimary ? '*' : cluster.worker!.id;
|
||||
const l =
|
||||
level === 'error' ? important ? chalk.bgRed.white('ERR ') : chalk.red('ERR ') :
|
||||
level === 'warning' ? chalk.yellow('WARN') :
|
||||
|
@ -85,7 +86,6 @@ export default class Logger {
|
|||
level === 'error' ? this.syslogClient.error :
|
||||
level === 'warning' ? this.syslogClient.warning :
|
||||
level === 'success' ? this.syslogClient.info :
|
||||
level === 'debug' ? this.syslogClient.info :
|
||||
level === 'info' ? this.syslogClient.info :
|
||||
null as never;
|
||||
|
||||
|
@ -94,7 +94,7 @@ export default class Logger {
|
|||
}
|
||||
}
|
||||
|
||||
public error(x: string | Error, data?: Record<string, any> = {}, important = false): void { // 実行を継続できない状況で使う
|
||||
public error(x: string | Error, data: Record<string, any> = {}, important = false): void { // 実行を継続できない状況で使う
|
||||
if (x instanceof Error) {
|
||||
data.e = x;
|
||||
this.log('error', x.toString(), data, important);
|
||||
|
|
Loading…
Reference in a new issue