Skip to content

Commit

Permalink
fixes loading of config vars
Browse files Browse the repository at this point in the history
  • Loading branch information
WahlMartin committed Nov 21, 2023
1 parent 23d4d17 commit da997f1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
18 changes: 9 additions & 9 deletions config/config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 4 additions & 1 deletion src/core/logging/module-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class ModuleLogger {
this.moduleNameInternal = moduleName;

const loggerConfig: LoggingConfig = configService.getOrThrow<LoggingConfig>('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<string> = loggerConfig[configKey] ?? loggerConfig.DEFAULT_LOG_LEVEL;
const loggerFormat: winston.Logform.Format = format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }),
Expand Down
10 changes: 0 additions & 10 deletions src/modules/person/api/person.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<PersonendatensatzResponse> {
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 = {
Expand Down
48 changes: 34 additions & 14 deletions src/shared/config/logging.config.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
import { IsNotEmpty, IsString } from 'class-validator';
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';

export class LoggingConfig {
@IsString()
@IsNotEmpty()
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;
}

0 comments on commit da997f1

Please sign in to comment.