Merge branch 'microservices' into 'main'

complete user and auth services logs

See merge request mobicoop/lab/v3/services/logger!2
This commit is contained in:
Gsk54 2022-12-26 14:21:39 +00:00
commit b78860fff7
2 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,73 @@
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 AuthController {
constructor(
@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
) {}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'auth.create.crit',
queue: 'logging-auth-create-crit',
})
public async authCreatedCriticalHandler(message: string) {
this.logger.configure(loggerOptions('auth', level.crit, 'critical'));
this.logger.crit(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'auth.delete.crit',
queue: 'logging-auth-delete-crit',
})
public async authDeletedCriticalHandler(message: string) {
this.logger.configure(loggerOptions('auth', level.crit, 'critical'));
this.logger.crit(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'auth.username.add.warning',
queue: 'logging-auth-username-add-warning',
})
public async authUsernameAddedWarningHandler(message: string) {
this.logger.configure(loggerOptions('auth', level.warning, 'warning'));
this.logger.warning(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'auth.username.delete.warning',
queue: 'logging-auth-username-delete-warning',
})
public async authUsernameDeletedWarningHandler(message: string) {
this.logger.configure(loggerOptions('auth', level.warning, 'warning'));
this.logger.warning(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'auth.password.update.warning',
queue: 'logging-auth-password-update-warning',
})
public async authPasswordUpdatedWarningHandler(message: string) {
this.logger.configure(loggerOptions('auth', level.warning, 'warning'));
this.logger.warning(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'auth.username.update.warning',
queue: 'logging-auth-username-update-warning',
})
public async authUsernameUpdatedWarningHandler(message: string) {
this.logger.configure(loggerOptions('auth', level.warning, 'warning'));
this.logger.warning(JSON.parse(message));
}
}

View File

@ -40,4 +40,54 @@ export class UserController {
this.logger.configure(loggerOptions('user', level.crit, 'critical')); this.logger.configure(loggerOptions('user', level.crit, 'critical'));
this.logger.crit(JSON.parse(message)); this.logger.crit(JSON.parse(message));
} }
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'user.delete.info',
queue: 'logging-user-delete-info',
})
public async userDeletedInfoHandler(message: string) {
this.logger.configure(loggerOptions('user', level.info, 'info'));
this.logger.info(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'user.delete.crit',
queue: 'logging-user-delete-crit',
})
public async userDeletedCriticalHandler(message: string) {
this.logger.configure(loggerOptions('user', level.crit, 'critical'));
this.logger.crit(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'user.read.warning',
queue: 'logging-user-read-warning',
})
public async userReadWarningHandler(message: string) {
this.logger.configure(loggerOptions('user', level.warning, 'warning'));
this.logger.warning(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'user.update.info',
queue: 'logging-user-update-info',
})
public async userUpdatedInfoHandler(message: string) {
this.logger.configure(loggerOptions('user', level.info, 'info'));
this.logger.info(JSON.parse(message));
}
@RabbitSubscribe({
exchange: 'logging',
routingKey: 'user.update.crit',
queue: 'logging-user-update-crit',
})
public async userUpdatedCriticalHandler(message: string) {
this.logger.configure(loggerOptions('user', level.crit, 'critical'));
this.logger.crit(JSON.parse(message));
}
} }