diff --git a/src/modules/logger/adapters/primaries/auth.controller.ts b/src/modules/logger/adapters/primaries/auth.controller.ts index 3f22d3e..8b6e494 100644 --- a/src/modules/logger/adapters/primaries/auth.controller.ts +++ b/src/modules/logger/adapters/primaries/auth.controller.ts @@ -17,7 +17,9 @@ export class AuthController { queue: 'logging-auth-create-crit', }) public async authCreatedCriticalHandler(message: string) { - this.logger.configure(loggerOptions('auth', level.crit, 'critical')); + this.logger.configure( + loggerOptions('auth', level.crit, 'critical', 'create'), + ); this.logger.crit(JSON.parse(message)); } @@ -27,7 +29,9 @@ export class AuthController { queue: 'logging-auth-delete-crit', }) public async authDeletedCriticalHandler(message: string) { - this.logger.configure(loggerOptions('auth', level.crit, 'critical')); + this.logger.configure( + loggerOptions('auth', level.crit, 'critical', 'delete'), + ); this.logger.crit(JSON.parse(message)); } @@ -37,7 +41,9 @@ export class AuthController { queue: 'logging-auth-username-add-warning', }) public async authUsernameAddedWarningHandler(message: string) { - this.logger.configure(loggerOptions('auth', level.warning, 'warning')); + this.logger.configure( + loggerOptions('auth', level.warning, 'warning', 'username-add'), + ); this.logger.warning(JSON.parse(message)); } @@ -47,7 +53,9 @@ export class AuthController { queue: 'logging-auth-username-delete-warning', }) public async authUsernameDeletedWarningHandler(message: string) { - this.logger.configure(loggerOptions('auth', level.warning, 'warning')); + this.logger.configure( + loggerOptions('auth', level.warning, 'warning', 'username-delete'), + ); this.logger.warning(JSON.parse(message)); } @@ -57,7 +65,9 @@ export class AuthController { queue: 'logging-auth-password-update-warning', }) public async authPasswordUpdatedWarningHandler(message: string) { - this.logger.configure(loggerOptions('auth', level.warning, 'warning')); + this.logger.configure( + loggerOptions('auth', level.warning, 'warning', 'password-update'), + ); this.logger.warning(JSON.parse(message)); } @@ -67,7 +77,9 @@ export class AuthController { queue: 'logging-auth-username-update-warning', }) public async authUsernameUpdatedWarningHandler(message: string) { - this.logger.configure(loggerOptions('auth', level.warning, 'warning')); + this.logger.configure( + loggerOptions('auth', level.warning, 'warning', 'username-update'), + ); this.logger.warning(JSON.parse(message)); } } diff --git a/src/modules/logger/adapters/primaries/logger/logger.ts b/src/modules/logger/adapters/primaries/logger/logger.ts index 1aabc13..9bce5be 100644 --- a/src/modules/logger/adapters/primaries/logger/logger.ts +++ b/src/modules/logger/adapters/primaries/logger/logger.ts @@ -7,8 +7,14 @@ export default function loggerOptions( dirname: string, level: level, filename: string, + label: string, ) { - const transportOptions = new TransportOptions(dirname, level, filename); + const transportOptions = new TransportOptions( + dirname, + level, + filename, + label, + ); const transport = new winston.transports.DailyRotateFile({ ...transportOptions, }); diff --git a/src/modules/logger/adapters/primaries/logger/transport.options.ts b/src/modules/logger/adapters/primaries/logger/transport.options.ts index 32be115..f93ae13 100644 --- a/src/modules/logger/adapters/primaries/logger/transport.options.ts +++ b/src/modules/logger/adapters/primaries/logger/transport.options.ts @@ -10,19 +10,21 @@ export class TransportOptions { filename = 'info'; level = levelEnum.info; dirname = 'logs'; + label = ''; format: winston.Logform.Format = winston.format.combine( filter(this.level), winston.format.timestamp(), winston.format.json(), ); - constructor(dir: string, level: levelEnum, filename: string) { + constructor(dir: string, level: levelEnum, filename: string, label: string) { this.level = level; this.filename = filename; this.dirname += '/' + dir; this.format = winston.format.combine( filter(this.level), winston.format.timestamp(), + winston.format.label({ label }), winston.format.json(), ); } diff --git a/src/modules/logger/adapters/primaries/user.controller.ts b/src/modules/logger/adapters/primaries/user.controller.ts index b4111aa..4323fba 100644 --- a/src/modules/logger/adapters/primaries/user.controller.ts +++ b/src/modules/logger/adapters/primaries/user.controller.ts @@ -17,7 +17,7 @@ export class UserController { queue: 'logging-user-create-info', }) public async userCreatedInfoHandler(message: string) { - this.logger.configure(loggerOptions('user', level.info, 'info')); + this.logger.configure(loggerOptions('user', level.info, 'info', 'create')); this.logger.info(JSON.parse(message)); } @@ -27,7 +27,9 @@ export class UserController { queue: 'logging-user-create-warning', }) public async userCreatedWarningHandler(message: string) { - this.logger.configure(loggerOptions('user', level.warning, 'warning')); + this.logger.configure( + loggerOptions('user', level.warning, 'warning', 'create'), + ); this.logger.warning(JSON.parse(message)); } @@ -37,7 +39,9 @@ export class UserController { queue: 'logging-user-create-crit', }) public async userCreatedCriticalHandler(message: string) { - this.logger.configure(loggerOptions('user', level.crit, 'critical')); + this.logger.configure( + loggerOptions('user', level.crit, 'critical', 'create'), + ); this.logger.crit(JSON.parse(message)); } @@ -47,7 +51,7 @@ export class UserController { queue: 'logging-user-delete-info', }) public async userDeletedInfoHandler(message: string) { - this.logger.configure(loggerOptions('user', level.info, 'info')); + this.logger.configure(loggerOptions('user', level.info, 'info', 'delete')); this.logger.info(JSON.parse(message)); } @@ -57,7 +61,9 @@ export class UserController { queue: 'logging-user-delete-crit', }) public async userDeletedCriticalHandler(message: string) { - this.logger.configure(loggerOptions('user', level.crit, 'critical')); + this.logger.configure( + loggerOptions('user', level.crit, 'critical', 'delete'), + ); this.logger.crit(JSON.parse(message)); } @@ -67,7 +73,9 @@ export class UserController { queue: 'logging-user-read-warning', }) public async userReadWarningHandler(message: string) { - this.logger.configure(loggerOptions('user', level.warning, 'warning')); + this.logger.configure( + loggerOptions('user', level.warning, 'warning', 'read'), + ); this.logger.warning(JSON.parse(message)); } @@ -77,7 +85,7 @@ export class UserController { queue: 'logging-user-update-info', }) public async userUpdatedInfoHandler(message: string) { - this.logger.configure(loggerOptions('user', level.info, 'info')); + this.logger.configure(loggerOptions('user', level.info, 'info', 'update')); this.logger.info(JSON.parse(message)); } @@ -87,7 +95,9 @@ export class UserController { queue: 'logging-user-update-crit', }) public async userUpdatedCriticalHandler(message: string) { - this.logger.configure(loggerOptions('user', level.crit, 'critical')); + this.logger.configure( + loggerOptions('user', level.crit, 'critical', 'update'), + ); this.logger.crit(JSON.parse(message)); } }