This commit is contained in:
sbriat 2023-06-29 11:49:07 +02:00
parent 7ed387f087
commit d7ec0e7da0
19 changed files with 394 additions and 329 deletions

View File

@ -31,7 +31,7 @@ The app runs automatically on the port defined in `SERVICE_PORT` of `.env` file
The app subscribes to RabbitMQ queues in order to log messages. We use the routing key with the given format : <**service**>.<**action**>.<**level**>, with : The app subscribes to RabbitMQ queues in order to log messages. We use the routing key with the given format : <**service**>.<**action**>.<**level**>, with :
- **service** : the name of the service that has emitted the message - **service** : the name of the service that has emitted the message
- **action** : the action that was at the origin of the message (one or more words separated by a dot) - **action** : the action that triggered the message (one or more words separated by a dot, last word should be )
- **level** : the severity (_log level_) of the message, as described in [RFC5424 syslog](https://www.rfc-editor.org/rfc/rfc5424) : - **level** : the severity (_log level_) of the message, as described in [RFC5424 syslog](https://www.rfc-editor.org/rfc/rfc5424) :
- **emer** : Emergency: system is unusable - **emer** : Emergency: system is unusable
- **alert** : Alert: action must be taken immediately - **alert** : Alert: action must be taken immediately
@ -44,10 +44,10 @@ The app subscribes to RabbitMQ queues in order to log messages. We use the routi
Examples of valid routing keys : Examples of valid routing keys :
- user.create.info - user.created.info
- user.create.crit - user.created.crit
- user.update.warning - user.updated.warning
- auth.username.add.info - auth.username.added.info
It is the responsibility of each service to set the routing key to the appropriate value. It is the responsibility of each service to set the routing key to the appropriate value.

View File

@ -1,7 +1,7 @@
import { HealthModule } from '@modules/health/health.module';
import { LoggerModule } from '@modules/logger/logger.module';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { LoggerModule } from './modules/logger.module';
import { HealthModule } from './modules/health/adapters/primaries/health.module';
@Module({ @Module({
imports: [ imports: [

View File

@ -1,7 +1,7 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { TerminusModule } from '@nestjs/terminus'; import { TerminusModule } from '@nestjs/terminus';
import { HttpModule } from '@nestjs/axios'; import { HttpModule } from '@nestjs/axios';
import { HealthController } from './health.controller'; import { HealthController } from './interface/http-controllers/health.http.controller';
@Module({ @Module({
imports: [TerminusModule, HttpModule], imports: [TerminusModule, HttpModule],

View File

@ -1,236 +0,0 @@
import { Module } from '@nestjs/common';
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { UserController } from './logger/adapters/primaries/user.controller';
import { WinstonModule } from 'nest-winston';
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';
import { AdminApiController } from './logger/adapters/primaries/admin-api.controller';
import { MatcherController } from './logger/adapters/primaries/matcher.controller';
import { AdController } from './logger/adapters/primaries/ad.controller';
@Module({
imports: [
RabbitMQModule.forRootAsync(RabbitMQModule, {
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
exchanges: [
{
name: configService.get<string>('RMQ_EXCHANGE'),
type: 'topic',
},
],
handlers: {
loggingGatewayApiHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.gateway-api.health.crit',
},
loggingAdminApiHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.admin-api.health.crit',
},
loggingAdCreateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.create.info',
},
loggingAdCreateWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.create.warning',
},
loggingAdCreateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.create.crit',
},
loggingAdDeleteInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.delete.info',
},
loggingAdDeleteCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.delete.crit',
},
loggingAdReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.read.warning',
},
loggingAdUpdateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.update.info',
},
loggingAdUpdateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.update.crit',
},
loggingAdHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.health.crit',
},
loggingAuthCreateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.create.crit',
},
loggingAuthDeleteCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.delete.crit',
},
loggingAuthUsernameAddWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.username.add.warning',
},
loggingAuthUsernameDeleteWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.username.delete.warning',
},
loggingAuthPasswordUpdateWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.password.update.warning',
},
loggingAuthUsernameUpdateWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.username.update.warning',
},
loggingAuthHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.health.crit',
},
loggingConfigurationCreateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.create.info',
},
loggingConfigurationCreateWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.create.warning',
},
loggingConfigurationCreateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.create.crit',
},
loggingConfigurationDeleteInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.delete.info',
},
loggingConfigurationDeleteCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.delete.crit',
},
loggingConfigurationReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.read.warning',
},
loggingConfigurationUpdateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.update.info',
},
loggingConfigurationUpdateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.update.crit',
},
loggingConfigurationHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.health.crit',
},
loggingMatcherMatchCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.matcher.match.crit',
},
loggingTerritoryCreateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.create.info',
},
loggingTerritoryCreateWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.create.warning',
},
loggingTerritoryCreateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.create.crit',
},
loggingTerritoryDeleteInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.delete.info',
},
loggingTerritoryDeleteCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.delete.crit',
},
loggingTerritoryReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.read.warning',
},
loggingTerritoryUpdateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.update.info',
},
loggingTerritoryUpdateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.update.crit',
},
loggingTerritoryHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.health.crit',
},
loggingUserCreateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.create.info',
},
loggingUserCreateWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.create.warning',
},
loggingUserCreateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.create.crit',
},
loggingUserDeleteInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.delete.info',
},
loggingUserDeleteCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.delete.crit',
},
loggingUserReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.read.warning',
},
loggingUserUpdateInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.update.info',
},
loggingUserUpdateCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.update.crit',
},
loggingUserHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.health.crit',
},
},
uri: configService.get<string>('RMQ_URI'),
connectionInitOptions: { wait: false },
enableControllerDiscovery: true,
}),
inject: [ConfigService],
}),
WinstonModule.forRoot({
levels: winston.config.syslog.levels,
transports: [],
}),
],
controllers: [
AdController,
AuthController,
UserController,
ConfigurationController,
MatcherController,
TerritoryController,
GatewayApiController,
AdminApiController,
],
providers: [],
exports: [],
})
export class LoggerModule {}

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import { level } from '../level.enum';
import loggerOptions from './logger/logger'; import loggerOptions from '../logger.options';
@Controller() @Controller()
export class AdController { export class AdController {
@ -12,47 +12,47 @@ export class AdController {
) {} ) {}
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAdCreateInfo', name: 'loggingAdCreatedInfo',
}) })
public async adCreatedInfoHandler(message: string) { public async adCreatedInfoHandler(message: string) {
this.logger.configure(loggerOptions('ad', level.info, 'info', 'create')); this.logger.configure(loggerOptions('ad', level.info, 'info', 'created'));
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAdCreateWarning', name: 'loggingAdCreatedWarning',
}) })
public async adCreatedWarningHandler(message: string) { public async adCreatedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('ad', level.warning, 'warning', 'create'), loggerOptions('ad', level.warning, 'warning', 'created'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAdCreateCrit', name: 'loggingAdCreatedCrit',
}) })
public async adCreatedCriticalHandler(message: string) { public async adCreatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('ad', level.crit, 'critical', 'create'), loggerOptions('ad', level.crit, 'critical', 'created'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAdDeleteInfo', name: 'loggingAdDeletedInfo',
}) })
public async adDeletedInfoHandler(message: string) { public async adDeletedInfoHandler(message: string) {
this.logger.configure(loggerOptions('ad', level.info, 'info', 'delete')); this.logger.configure(loggerOptions('ad', level.info, 'info', 'deleted'));
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAdDeleteCrit', name: 'loggingAdDeletedCrit',
}) })
public async adDeletedCriticalHandler(message: string) { public async adDeletedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('ad', level.crit, 'critical', 'delete'), loggerOptions('ad', level.crit, 'critical', 'deleted'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@ -68,19 +68,19 @@ export class AdController {
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAdUpdateInfo', name: 'loggingAdUpdatedInfo',
}) })
public async adUpdatedInfoHandler(message: string) { public async adUpdatedInfoHandler(message: string) {
this.logger.configure(loggerOptions('ad', level.info, 'info', 'update')); this.logger.configure(loggerOptions('ad', level.info, 'info', 'updated'));
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAdUpdateCrit', name: 'loggingAdUpdatedCrit',
}) })
public async adUpdatedCriticalHandler(message: string) { public async adUpdatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('ad', level.crit, 'critical', 'update'), loggerOptions('ad', level.crit, 'critical', 'updated'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import loggerOptions from '../logger.options';
import loggerOptions from './logger/logger'; import { level } from '../level.enum';
@Controller() @Controller()
export class AdminApiController { export class AdminApiController {

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import loggerOptions from '../logger.options';
import loggerOptions from './logger/logger'; import { level } from '../level.enum';
@Controller() @Controller()
export class AuthController { export class AuthController {
@ -12,61 +12,61 @@ export class AuthController {
) {} ) {}
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAuthCreateCrit', name: 'loggingAuthCreatedCrit',
}) })
public async authCreatedCriticalHandler(message: string) { public async authCreatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('auth', level.crit, 'critical', 'create'), loggerOptions('auth', level.crit, 'critical', 'created'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAuthDeleteCrit', name: 'loggingAuthDeletedCrit',
}) })
public async authDeletedCriticalHandler(message: string) { public async authDeletedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('auth', level.crit, 'critical', 'delete'), loggerOptions('auth', level.crit, 'critical', 'deleted'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAuthUsernameAddWarning', name: 'loggingAuthUsernameAddedWarning',
}) })
public async authUsernameAddedWarningHandler(message: string) { public async authUsernameAddedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('auth', level.warning, 'warning', 'username-add'), loggerOptions('auth', level.warning, 'warning', 'username-added'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAuthUsernameDeleteWarning', name: 'loggingAuthUsernameDeletedWarning',
}) })
public async authUsernameDeletedWarningHandler(message: string) { public async authUsernameDeletedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('auth', level.warning, 'warning', 'username-delete'), loggerOptions('auth', level.warning, 'warning', 'username-deleted'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAuthPasswordUpdateWarning', name: 'loggingAuthPasswordUpdatedWarning',
}) })
public async authPasswordUpdatedWarningHandler(message: string) { public async authPasswordUpdatedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('auth', level.warning, 'warning', 'password-update'), loggerOptions('auth', level.warning, 'warning', 'password-updated'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingAuthUsernameUpdateWarning', name: 'loggingAuthUsernameUpdatedWarning',
}) })
public async authUsernameUpdatedWarningHandler(message: string) { public async authUsernameUpdatedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('auth', level.warning, 'warning', 'username-update'), loggerOptions('auth', level.warning, 'warning', 'username-updated'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import loggerOptions from '../logger.options';
import loggerOptions from './logger/logger'; import { level } from '../level.enum';
@Controller() @Controller()
export class ConfigurationController { export class ConfigurationController {
@ -12,51 +12,51 @@ export class ConfigurationController {
) {} ) {}
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingConfigurationCreateInfo', name: 'loggingConfigurationCreatedInfo',
}) })
public async configurationCreatedInfoHandler(message: string) { public async configurationCreatedInfoHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('configuration', level.info, 'info', 'create'), loggerOptions('configuration', level.info, 'info', 'created'),
); );
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingConfigurationCreateWarning', name: 'loggingConfigurationCreatedWarning',
}) })
public async configurationCreatedWarningHandler(message: string) { public async configurationCreatedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('configuration', level.warning, 'warning', 'create'), loggerOptions('configuration', level.warning, 'warning', 'created'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingConfigurationCreateCrit', name: 'loggingConfigurationCreatedCrit',
}) })
public async configurationCreatedCriticalHandler(message: string) { public async configurationCreatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('configuration', level.crit, 'critical', 'create'), loggerOptions('configuration', level.crit, 'critical', 'created'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingConfigurationDeleteInfo', name: 'loggingConfigurationDeletedInfo',
}) })
public async configurationDeletedInfoHandler(message: string) { public async configurationDeletedInfoHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('configuration', level.info, 'info', 'delete'), loggerOptions('configuration', level.info, 'info', 'deleted'),
); );
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingConfigurationDeleteCrit', name: 'loggingConfigurationDeletedCrit',
}) })
public async configurationDeletedCriticalHandler(message: string) { public async configurationDeletedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('configuration', level.crit, 'critical', 'delete'), loggerOptions('configuration', level.crit, 'critical', 'deleted'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@ -72,21 +72,21 @@ export class ConfigurationController {
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingConfigurationUpdateInfo', name: 'loggingConfigurationUpdatedInfo',
}) })
public async configurationUpdatedInfoHandler(message: string) { public async configurationUpdatedInfoHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('configuration', level.info, 'info', 'update'), loggerOptions('configuration', level.info, 'info', 'updated'),
); );
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingConfigurationUpdateCrit', name: 'loggingConfigurationUpdatedCrit',
}) })
public async configurationUpdatedCriticalHandler(message: string) { public async configurationUpdatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('configuration', level.crit, 'critical', 'update'), loggerOptions('configuration', level.crit, 'critical', 'updated'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import loggerOptions from '../logger.options';
import loggerOptions from './logger/logger'; import { level } from '../level.enum';
@Controller() @Controller()
export class GatewayApiController { export class GatewayApiController {

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import { level } from '../level.enum';
import loggerOptions from './logger/logger'; import loggerOptions from '../logger.options';
@Controller() @Controller()
export class MatcherController { export class MatcherController {
@ -11,6 +11,16 @@ export class MatcherController {
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger, @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
) {} ) {}
@RabbitSubscribe({
name: 'loggingMatcherAdCrit',
})
public async matcherAdCriticalHandler(message: string) {
this.logger.configure(
loggerOptions('matcher', level.crit, 'critical', 'ad'),
);
this.logger.crit(JSON.parse(message));
}
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingMatcherMatchCrit', name: 'loggingMatcherMatchCrit',
}) })

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import loggerOptions from '../logger.options';
import loggerOptions from './logger/logger'; import { level } from '../level.enum';
@Controller() @Controller()
export class TerritoryController { export class TerritoryController {
@ -12,51 +12,51 @@ export class TerritoryController {
) {} ) {}
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingTerritoryCreateInfo', name: 'loggingTerritoryCreatedInfo',
}) })
public async territoryCreatedInfoHandler(message: string) { public async territoryCreatedInfoHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('territory', level.info, 'info', 'create'), loggerOptions('territory', level.info, 'info', 'created'),
); );
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingTerritoryCreateWarning', name: 'loggingTerritoryCreatedWarning',
}) })
public async territoryCreatedWarningHandler(message: string) { public async territoryCreatedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('territory', level.warning, 'warning', 'create'), loggerOptions('territory', level.warning, 'warning', 'created'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingTerritoryCreateCrit', name: 'loggingTerritoryCreatedCrit',
}) })
public async territoryCreatedCriticalHandler(message: string) { public async territoryCreatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('territory', level.crit, 'critical', 'create'), loggerOptions('territory', level.crit, 'critical', 'created'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingTerritoryDeleteInfo', name: 'loggingTerritoryDeletedInfo',
}) })
public async territoryDeletedInfoHandler(message: string) { public async territoryDeletedInfoHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('territory', level.info, 'info', 'delete'), loggerOptions('territory', level.info, 'info', 'deleted'),
); );
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingTerritoryDeleteCrit', name: 'loggingTerritoryDeletedCrit',
}) })
public async territoryDeletedCriticalHandler(message: string) { public async territoryDeletedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('territory', level.crit, 'critical', 'delete'), loggerOptions('territory', level.crit, 'critical', 'deleted'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@ -72,21 +72,21 @@ export class TerritoryController {
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingTerritoryUpdateInfo', name: 'loggingTerritoryUpdatedInfo',
}) })
public async territoryUpdatedInfoHandler(message: string) { public async territoryUpdatedInfoHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('territory', level.info, 'info', 'update'), loggerOptions('territory', level.info, 'info', 'updated'),
); );
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingTerritoryUpdateCrit', name: 'loggingTerritoryUpdatedCrit',
}) })
public async territoryUpdatedCriticalHandler(message: string) { public async territoryUpdatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('territory', level.crit, 'critical', 'update'), loggerOptions('territory', level.crit, 'critical', 'updated'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }

View File

@ -2,8 +2,8 @@ import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq';
import { Controller, Inject } from '@nestjs/common'; import { Controller, Inject } from '@nestjs/common';
import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
import { Logger } from 'winston'; import { Logger } from 'winston';
import { level } from './logger/level.enum'; import loggerOptions from '../logger.options';
import loggerOptions from './logger/logger'; import { level } from '../level.enum';
@Controller() @Controller()
export class UserController { export class UserController {
@ -12,47 +12,47 @@ export class UserController {
) {} ) {}
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingUserCreateInfo', name: 'loggingUserCreatedInfo',
}) })
public async userCreatedInfoHandler(message: string) { public async userCreatedInfoHandler(message: string) {
this.logger.configure(loggerOptions('user', level.info, 'info', 'create')); this.logger.configure(loggerOptions('user', level.info, 'info', 'created'));
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingUserCreateWarning', name: 'loggingUserCreatedWarning',
}) })
public async userCreatedWarningHandler(message: string) { public async userCreatedWarningHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('user', level.warning, 'warning', 'create'), loggerOptions('user', level.warning, 'warning', 'created'),
); );
this.logger.warning(JSON.parse(message)); this.logger.warning(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingUserCreateCrit', name: 'loggingUserCreatedCrit',
}) })
public async userCreatedCriticalHandler(message: string) { public async userCreatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('user', level.crit, 'critical', 'create'), loggerOptions('user', level.crit, 'critical', 'created'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingUserDeleteInfo', name: 'loggingUserDeletedInfo',
}) })
public async userDeletedInfoHandler(message: string) { public async userDeletedInfoHandler(message: string) {
this.logger.configure(loggerOptions('user', level.info, 'info', 'delete')); this.logger.configure(loggerOptions('user', level.info, 'info', 'deleted'));
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingUserDeleteCrit', name: 'loggingUserDeletedCrit',
}) })
public async userDeletedCriticalHandler(message: string) { public async userDeletedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('user', level.crit, 'critical', 'delete'), loggerOptions('user', level.crit, 'critical', 'deleted'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@ -68,19 +68,19 @@ export class UserController {
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingUserUpdateInfo', name: 'loggingUserUpdatedInfo',
}) })
public async userUpdatedInfoHandler(message: string) { public async userUpdatedInfoHandler(message: string) {
this.logger.configure(loggerOptions('user', level.info, 'info', 'update')); this.logger.configure(loggerOptions('user', level.info, 'info', 'updated'));
this.logger.info(JSON.parse(message)); this.logger.info(JSON.parse(message));
} }
@RabbitSubscribe({ @RabbitSubscribe({
name: 'loggingUserUpdateCrit', name: 'loggingUserUpdatedCrit',
}) })
public async userUpdatedCriticalHandler(message: string) { public async userUpdatedCriticalHandler(message: string) {
this.logger.configure( this.logger.configure(
loggerOptions('user', level.crit, 'critical', 'update'), loggerOptions('user', level.crit, 'critical', 'updated'),
); );
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }

View File

@ -0,0 +1,287 @@
import { Module } from '@nestjs/common';
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { WinstonModule } from 'nest-winston';
import * as winston from 'winston';
import { AdController } from './interface/message-controllers/ad.controller';
import { AuthController } from './interface/message-controllers/auth.controller';
import { UserController } from './interface/message-controllers/user.controller';
import { ConfigurationController } from './interface/message-controllers/configuration.controller';
import { MatcherController } from './interface/message-controllers/matcher.controller';
import { TerritoryController } from './interface/message-controllers/territory.controller';
import { GatewayApiController } from './interface/message-controllers/gateway-api.controller';
import { AdminApiController } from './interface/message-controllers/admin-api.controller';
@Module({
imports: [
RabbitMQModule.forRootAsync(RabbitMQModule, {
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
exchanges: [
{
name: configService.get<string>('RMQ_EXCHANGE'),
type: 'topic',
},
],
handlers: {
loggingGatewayApiHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.gateway-api.health.crit',
queue: 'logging-gateway-api-health-crit',
},
loggingAdminApiHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.admin-api.health.crit',
queue: 'logging-admin-api-health-crit',
},
loggingAdCreatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.created.info',
queue: 'logging-ad-created-info',
},
loggingAdCreatedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.created.warning',
queue: 'logging-ad-created-warning',
},
loggingAdCreatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.created.crit',
queue: 'logging-ad-created-crit',
},
loggingAdDeletedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.deleted.info',
queue: 'logging-ad-deleted-info',
},
loggingAdDeletedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.deleted.crit',
queue: 'logging-ad-deleted-crit',
},
loggingAdReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.read.warning',
queue: 'logging-ad-read-warning',
},
loggingAdUpdatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.updated.info',
queue: 'logging-ad-updated-info',
},
loggingAdUpdatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.updated.crit',
queue: 'logging-ad-updated-crit',
},
loggingAdHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.ad.health.crit',
queue: 'logging-ad-health-crit',
},
loggingAuthCreatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.created.crit',
queue: 'logging-auth-created-crit',
},
loggingAuthDeletedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.deleted.crit',
queue: 'logging-auth-deleted-crit',
},
loggingAuthUsernameAddedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.username.added.warning',
queue: 'logging-auth-username-added-warning',
},
loggingAuthUsernameDeletedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.username.deleted.warning',
queue: 'logging-auth-username-deleted-warning',
},
loggingAuthPasswordUpdatedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.password.updated.warning',
queue: 'logging-auth-password-updated-warning',
},
loggingAuthUsernameUpdatedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.username.updated.warning',
queue: 'logging-auth-username-updated-warning',
},
loggingAuthHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.auth.health.crit',
queue: 'logging-auth-health-crit',
},
loggingConfigurationCreatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.created.info',
queue: 'logging-configuration-created-info',
},
loggingConfigurationCreatedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.created.warning',
queue: 'logging-configuration-created-warning',
},
loggingConfigurationCreatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.created.crit',
queue: 'logging-configuration-created-crit',
},
loggingConfigurationDeletedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.deleted.info',
queue: 'logging-configuration-deleted-info',
},
loggingConfigurationDeletedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.deleted.crit',
queue: 'logging-configuration-deleted-crit',
},
loggingConfigurationReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.read.warning',
queue: 'logging-configuration-read-warning',
},
loggingConfigurationUpdatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.updated.info',
queue: 'logging-configuration-updated-info',
},
loggingConfigurationUpdatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.updated.crit',
queue: 'logging-configuration-updated-crit',
},
loggingConfigurationHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.configuration.health.crit',
queue: 'logging-configuration-health-crit',
},
loggingMatcherAdCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.matcher.ad.crit',
queue: 'logging-matcher-ad-crit',
},
loggingMatcherMatchCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.matcher.match.crit',
queue: 'logging-matcher-match-crit',
},
loggingTerritoryCreatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.created.info',
queue: 'logging-territory-created-info',
},
loggingTerritoryCreatedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.created.warning',
queue: 'logging-territory-created-warning',
},
loggingTerritoryCreatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.created.crit',
queue: 'logging-territory-created-crit',
},
loggingTerritoryDeletedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.deleted.info',
queue: 'logging-territory-deleted-info',
},
loggingTerritoryDeletedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.deleted.crit',
queue: 'logging-territory-deleted-crit',
},
loggingTerritoryReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.read.warning',
queue: 'logging-territory-read-warning',
},
loggingTerritoryUpdatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.updated.info',
queue: 'logging-territory-updated-info',
},
loggingTerritoryUpdatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.updated.crit',
queue: 'logging-territory-updated-crit',
},
loggingTerritoryHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.territory.health.crit',
queue: 'logging-territory-health-crit',
},
loggingUserCreatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.created.info',
queue: 'logging-user-created-info',
},
loggingUserCreatedWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.created.warning',
queue: 'logging-user-created-warning',
},
loggingUserCreatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.created.crit',
queue: 'logging-user-created-crit',
},
loggingUserDeletedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.deleted.info',
queue: 'logging-user-deleted-info',
},
loggingUserDeletedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.deleted.crit',
queue: 'logging-user-deleted-crit',
},
loggingUserReadWarning: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.read.warning',
queue: 'logging-user-read-warning',
},
loggingUserUpdatedInfo: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.updated.info',
queue: 'logging-user-updated-info',
},
loggingUserUpdatedCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.updated.crit',
queue: 'logging-user-updated-crit',
},
loggingUserHealthCrit: {
exchange: configService.get<string>('RMQ_EXCHANGE'),
routingKey: 'logging.user.health.crit',
queue: 'logging-user-health-crit',
},
},
uri: configService.get<string>('RMQ_URI'),
connectionInitOptions: { wait: false },
enableControllerDiscovery: true,
}),
inject: [ConfigService],
}),
WinstonModule.forRoot({
levels: winston.config.syslog.levels,
transports: [],
}),
],
controllers: [
AdController,
AuthController,
UserController,
ConfigurationController,
MatcherController,
TerritoryController,
GatewayApiController,
AdminApiController,
],
providers: [],
exports: [],
})
export class LoggerModule {}

View File

@ -16,6 +16,10 @@
"noImplicitAny": false, "noImplicitAny": false,
"strictBindCallApply": false, "strictBindCallApply": false,
"forceConsistentCasingInFileNames": false, "forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false "noFallthroughCasesInSwitch": false,
"paths": {
"@modules/*": ["src/modules/*"],
"@src/*": ["src/*"]
}
} }
} }