diff --git a/lib/health-check/health-check.service.spec.ts b/lib/health-check/health-check.service.spec.ts index b61260602..645727f68 100644 --- a/lib/health-check/health-check.service.spec.ts +++ b/lib/health-check/health-check.service.spec.ts @@ -4,7 +4,7 @@ import { HealthCheckExecutor } from './health-check-executor.service'; import { ERROR_LOGGER } from './error-logger/error-logger.provider'; import { ErrorLogger } from './error-logger/error-logger.interface'; import { TERMINUS_LOGGER } from './logger/logger.provider'; -import { ConsoleLogger } from '@nestjs/common'; +import { ConsoleLogger, LoggerService } from '@nestjs/common'; const healthCheckExecutorMock: Partial = { execute: jest.fn(), @@ -14,8 +14,7 @@ const errorLoggerMock: ErrorLogger = { getErrorMessage: jest.fn(), }; -const loggerMock: Partial = { - setContext: jest.fn(), +const loggerMock: Partial = { log: jest.fn(), error: jest.fn(), warn: jest.fn(), @@ -25,7 +24,7 @@ const loggerMock: Partial = { describe('HealthCheckService', () => { let healthCheckExecutor: HealthCheckExecutor; let healthCheckService: HealthCheckService; - let logger: ConsoleLogger; + let logger: LoggerService; let errorLogger: ErrorLogger; beforeEach(async () => { diff --git a/lib/health-check/health-check.service.ts b/lib/health-check/health-check.service.ts index d10e05d6b..d151a50aa 100644 --- a/lib/health-check/health-check.service.ts +++ b/lib/health-check/health-check.service.ts @@ -3,6 +3,7 @@ import { ServiceUnavailableException, Inject, ConsoleLogger, + LoggerService, } from '@nestjs/common'; import { HealthIndicatorFunction } from '../health-indicator'; import { ErrorLogger } from './error-logger/error-logger.interface'; @@ -22,9 +23,11 @@ export class HealthCheckService { @Inject(ERROR_LOGGER) private readonly errorLogger: ErrorLogger, @Inject(TERMINUS_LOGGER) - private readonly logger: ConsoleLogger, + private readonly logger: LoggerService, ) { - this.logger.setContext(HealthCheckService.name); + if (this.logger instanceof ConsoleLogger) { + this.logger.setContext(HealthCheckService.name); + } } /**