diff --git a/src/modules/logger.module.ts b/src/modules/logger.module.ts index 02e2d62..dddcbc1 100644 --- a/src/modules/logger.module.ts +++ b/src/modules/logger.module.ts @@ -7,6 +7,7 @@ import * as winston from 'winston'; import { AuthController } from './logger/adapters/primaries/auth.controller'; import { ConfigurationController } from './logger/adapters/primaries/configuration.controller'; import { TerritoryController } from './logger/adapters/primaries/territory.controller'; +import { GatewayApiController } from './logger/adapters/primaries/gateway-api.controller'; @Module({ imports: [ @@ -20,6 +21,10 @@ import { TerritoryController } from './logger/adapters/primaries/territory.contr }, ], handlers: { + loggingGatewayApiHealthCrit: { + exchange: configService.get('RMQ_EXCHANGE'), + routingKey: 'logging.gateway-api.health.crit', + }, loggingAuthCreateCrit: { exchange: configService.get('RMQ_EXCHANGE'), routingKey: 'logging.auth.create.crit', @@ -157,6 +162,7 @@ import { TerritoryController } from './logger/adapters/primaries/territory.contr UserController, ConfigurationController, TerritoryController, + GatewayApiController, ], providers: [], exports: [], diff --git a/src/modules/logger/adapters/primaries/gateway-api.controller.ts b/src/modules/logger/adapters/primaries/gateway-api.controller.ts new file mode 100644 index 0000000..6a45503 --- /dev/null +++ b/src/modules/logger/adapters/primaries/gateway-api.controller.ts @@ -0,0 +1,23 @@ +import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq'; +import { Controller, Inject } from '@nestjs/common'; +import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; +import { Logger } from 'winston'; +import { level } from './logger/level.enum'; +import loggerOptions from './logger/logger'; + +@Controller() +export class GatewayApiController { + constructor( + @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger, + ) {} + + @RabbitSubscribe({ + name: 'loggingGatewayApiHealthCrit', + }) + public async gatewayApiHealthCriticalHandler(message: string) { + this.logger.configure( + loggerOptions('gateway-api', level.crit, 'crit', 'health'), + ); + this.logger.crit(JSON.parse(message)); + } +} diff --git a/src/modules/logger/adapters/primaries/logger/transport.options.ts b/src/modules/logger/adapters/primaries/logger/transport.options.ts index f93ae13..9836049 100644 --- a/src/modules/logger/adapters/primaries/logger/transport.options.ts +++ b/src/modules/logger/adapters/primaries/logger/transport.options.ts @@ -3,7 +3,7 @@ import * as winston from 'winston'; import { level as levelEnum } from './level.enum'; export class TransportOptions { - extension = '.log'; + extension = '.json'; maxSize = '1m'; maxFiles = '60'; zippedArchive = true;