From 4b6c60da457ce95f986df091fd3fa41f508fc9a1 Mon Sep 17 00:00:00 2001 From: sbriat Date: Fri, 31 Mar 2023 17:34:47 +0200 Subject: [PATCH 1/2] admin api logs --- src/modules/logger.module.ts | 6 +++++ .../primaries/admin-api.controller.ts | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/modules/logger/adapters/primaries/admin-api.controller.ts diff --git a/src/modules/logger.module.ts b/src/modules/logger.module.ts index dddcbc1..c57df59 100644 --- a/src/modules/logger.module.ts +++ b/src/modules/logger.module.ts @@ -8,6 +8,7 @@ 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'; +import { AdminApiController } from './logger/adapters/primaries/admin-api.controller'; @Module({ imports: [ @@ -25,6 +26,10 @@ import { GatewayApiController } from './logger/adapters/primaries/gateway-api.co exchange: configService.get('RMQ_EXCHANGE'), routingKey: 'logging.gateway-api.health.crit', }, + loggingAdminApiHealthCrit: { + exchange: configService.get('RMQ_EXCHANGE'), + routingKey: 'logging.admin-api.health.crit', + }, loggingAuthCreateCrit: { exchange: configService.get('RMQ_EXCHANGE'), routingKey: 'logging.auth.create.crit', @@ -163,6 +168,7 @@ import { GatewayApiController } from './logger/adapters/primaries/gateway-api.co ConfigurationController, TerritoryController, GatewayApiController, + AdminApiController, ], providers: [], exports: [], diff --git a/src/modules/logger/adapters/primaries/admin-api.controller.ts b/src/modules/logger/adapters/primaries/admin-api.controller.ts new file mode 100644 index 0000000..af88431 --- /dev/null +++ b/src/modules/logger/adapters/primaries/admin-api.controller.ts @@ -0,0 +1,24 @@ +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 AdminApiController { + constructor( + @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger, + ) {} + + @RabbitSubscribe({ + name: 'loggingAdminApiHealthCrit', + }) + public async adminApiHealthCriticalHandler(message: string) { + console.log('ici'); + this.logger.configure( + loggerOptions('admin-api', level.crit, 'crit', 'health'), + ); + this.logger.crit(JSON.parse(message)); + } +} From 0bbc39ef524eb39c7c7313f767fbb81db55af059 Mon Sep 17 00:00:00 2001 From: sbriat Date: Fri, 31 Mar 2023 17:41:21 +0200 Subject: [PATCH 2/2] change extension for logs --- .../logger/adapters/primaries/logger/transport.options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/logger/adapters/primaries/logger/transport.options.ts b/src/modules/logger/adapters/primaries/logger/transport.options.ts index 9836049..f93ae13 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 = '.json'; + extension = '.log'; maxSize = '1m'; maxFiles = '60'; zippedArchive = true;