From da997f1899a23f8fcac7a729504c75a2eb2d3afa Mon Sep 17 00:00:00 2001 From: mawahl Date: Tue, 21 Nov 2023 10:55:16 +0100 Subject: [PATCH] fixes loading of config vars --- config/config.dev.json | 18 ++++---- src/core/logging/module-logger.ts | 5 ++- src/modules/person/api/person.controller.ts | 10 ----- src/shared/config/logging.config.ts | 48 +++++++++++++++------ 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/config/config.dev.json b/config/config.dev.json index 85f176116..282e4ed34 100644 --- a/config/config.dev.json +++ b/config/config.dev.json @@ -36,14 +36,14 @@ }, "LOGGING": { "DEFAULT_LOG_LEVEL": "info", - "PERSONMODULE_LOG_LEVEL": "debug", - "PERSONAPIMODULE_LOG_LEVEL": "debug", - "ORGANISATIONMODULE_LOG_LEVEL": "debug", - "ORGANISATIONAPIMODULE_LOG_LEVEL": "debug", - "ROLLEMODULE_LOG_LEVEL": "debug", - "ROLLEAPIMODULE_LOG_LEVEL": "debug", - "KEYCLOAKADMINISTRATIONMODULE_LOG_LEVEL": "debug", - "HEALTHMODULE_LOG_LEVEL": "debug", - "BACKENDFORFRONTENDMODULE_LOG_LEVEL": "debug" + "PERSON_MODULE_LOG_LEVEL": "debug", + "PERSON_API_MODULE_LOG_LEVEL": "debug", + "ORGANISATION_MODULE_LOG_LEVEL": "debug", + "ORGANISATION_API_MODULE_LOG_LEVEL": "debug", + "ROLLE_MODULE_LOG_LEVEL": "debug", + "ROLLE_API_MODULE_LOG_LEVEL": "debug", + "KEYCLOAK_ADMINISTRATION_MODULE_LOG_LEVEL": "debug", + "HEALTH_MODULE_LOG_LEVEL": "debug", + "BACKEND_FOR_FRONTEND_MODULE_LOG_LEVEL": "debug" } } diff --git a/src/core/logging/module-logger.ts b/src/core/logging/module-logger.ts index b072e2ca8..5bcda27ba 100644 --- a/src/core/logging/module-logger.ts +++ b/src/core/logging/module-logger.ts @@ -44,7 +44,10 @@ export class ModuleLogger { this.moduleNameInternal = moduleName; const loggerConfig: LoggingConfig = configService.getOrThrow('LOGGING'); - const configKey: keyof LoggingConfig = `${moduleName.split(/(?=[A-Z])/).join('_').toUpperCase()}_LOG_LEVEL` as keyof LoggingConfig; + const configKey: keyof LoggingConfig = `${moduleName + .split(/(?=[A-Z])/) + .join('_') + .toUpperCase()}_LOG_LEVEL` as keyof LoggingConfig; const level: Option = loggerConfig[configKey] ?? loggerConfig.DEFAULT_LOG_LEVEL; const loggerFormat: winston.Logform.Format = format.combine( format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }), diff --git a/src/modules/person/api/person.controller.ts b/src/modules/person/api/person.controller.ts index 429590a5a..9ef8cb62a 100644 --- a/src/modules/person/api/person.controller.ts +++ b/src/modules/person/api/person.controller.ts @@ -45,14 +45,12 @@ import { PersonenkontextQueryParams } from './personenkontext-query.params.js'; import { PersonenkontextDto } from './personenkontext.dto.js'; import { PersonenkontextResponse } from './personenkontext.response.js'; import { PersonenkontextUc } from './personenkontext.uc.js'; -import { ClassLogger } from '../../../core/logging/class-logger.js'; @ApiTags('personen') @Controller({ path: 'personen' }) @Public() export class PersonController { public constructor( - private readonly logger: ClassLogger, private readonly personUc: PersonUc, private readonly personenkontextUc: PersonenkontextUc, @Inject(getMapperToken()) private readonly mapper: Mapper, @@ -66,14 +64,6 @@ export class PersonController { @ApiForbiddenResponse({ description: 'Insufficient permissions to create the person.' }) @ApiInternalServerErrorResponse({ description: 'Internal server error while creating the person.' }) public async createPerson(@Body() params: CreatePersonBodyParams): Promise { - this.logger.emerg('This is an emerg message'); - this.logger.alert('this is an alert message'); - this.logger.crit('this is a crit message'); - this.logger.error('this is an error message'); - this.logger.warning('this is a warning message'); - this.logger.notice('this is a notice message'); - this.logger.info('this is an info message'); - this.logger.debug('this is a debug message'); const dto: CreatePersonDto = this.mapper.map(params, CreatePersonBodyParams, CreatePersonDto); const person: PersonDto = await this.personUc.createPerson(dto); const personendatensatzDto: PersonendatensatzDto = { diff --git a/src/shared/config/logging.config.ts b/src/shared/config/logging.config.ts index 4dafbaee4..c1c572899 100644 --- a/src/shared/config/logging.config.ts +++ b/src/shared/config/logging.config.ts @@ -1,4 +1,4 @@ -import { IsNotEmpty, IsString } from 'class-validator'; +import { IsNotEmpty, IsOptional, IsString } from 'class-validator'; export class LoggingConfig { @IsString() @@ -6,30 +6,50 @@ export class LoggingConfig { public readonly DEFAULT_LOG_LEVEL!: string; //Domain Modules + @IsOptional() + @IsString() + public readonly PERSON_MODULE_LOG_LEVEL?: string; - public readonly PERSONMODULE_LOG_LEVEL?: string; - - public readonly ORGANISATIONMODULE_LOG_LEVEL?: string; + @IsOptional() + @IsString() + public readonly ORGANISATION_MODULE_LOG_LEVEL?: string; - public readonly ROLLEMODULE_LOG_LEVEL?: string; + @IsOptional() + @IsString() + public readonly ROLLE_MODULE_LOG_LEVEL?: string; //API Modules + @IsOptional() + @IsString() + public readonly PERSON_API_MODULE_LOG_LEVEL?: string; - public readonly PERSON_API_MODULE_LOG_LEVEL!: string; - - public readonly ORGANISATIONAPIMODULE_LOG_LEVEL?: string; + @IsOptional() + @IsString() + public readonly ORGANISATION_API_MODULE_LOG_LEVEL?: string; - public readonly ROLLEAPIMODULE_LOG_LEVEL?: string; + @IsOptional() + @IsString() + public readonly ROLLE_API_MODULE_LOG_LEVEL?: string; //Technical Modules + @IsOptional() + @IsString() + public readonly SERVER_MODULE_LOG_LEVEL?: string; - public readonly KEYCLOAKADMINISTRATIONMODULE_LOG_LEVEL?: string; + @IsOptional() + @IsString() + public readonly KEYCLOAK_ADMINISTRATION_MODULE_LOG_LEVEL?: string; - public readonly HEALTHMODULE_LOG_LEVEL?: string; + @IsOptional() + @IsString() + public readonly HEALTH_MODULE_LOG_LEVEL?: string; //SPSH Modules + @IsOptional() + @IsString() + public readonly BACKEND_FOR_FRONTEND_MODULE_LOG_LEVEL?: string; - public readonly BACKENDFORFRONTENDMODULE_LOG_LEVEL?: string; - - public readonly UIBACKENDMODULE_LOG_LEVEL?: string; + @IsString() + @IsOptional() + public readonly UI_BACKEND_MODULE_LOG_LEVEL?: string; }