add new Console global DI to abstract the node.js console

This commit is contained in:
Hazelnoot 2025-10-08 17:01:11 -04:00
parent 8059515db4
commit 9b99e8eba8
4 changed files with 24 additions and 19 deletions

View file

@ -6,24 +6,24 @@
import { Inject, Injectable } from '@nestjs/common';
import Logger from '@/logger.js';
import { TimeService } from '@/global/TimeService.js';
import { EnvService } from '@/global/EnvService.js';
import { bindThis } from '@/decorators.js';
import type { KEYWORD } from 'color-convert/conversions.js';
import { envOption } from '@/env.js'; // TODO move to envService
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import type { KEYWORD } from 'color-convert/conversions.js';
@Injectable()
export class LoggerService {
constructor(
@Inject(DI.config)
private config: Config,
private readonly timeService: TimeService,
@Inject(DI.console)
protected readonly console: Console,
protected readonly timeService: TimeService,
protected readonly envService: EnvService,
) {
}
@bindThis
public getLogger(domain: string, color?: KEYWORD | undefined) {
const verbose = this.config.logging?.verbose || envOption.verbose;
return new Logger(domain, color, verbose, undefined, this.timeService);
return new Logger(domain, color, this.envService, this.timeService, this.console);
}
}