From f8035099c96d73f65fc42eeb14b39ed0cf9deb29 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Tue, 29 Apr 2025 12:05:53 +0200 Subject: [PATCH] refactor: Verbeter logging --- backend/.env.test | 6 ++++++ backend/src/orm.ts | 11 ++++++++--- backend/tool/seed.ts | 4 +--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/.env.test b/backend/.env.test index fb94aa09..e76cbe2b 100644 --- a/backend/.env.test +++ b/backend/.env.test @@ -4,6 +4,8 @@ # Should not need to be modified. # See .env.example for more information. # +### Advanced configuration ### + ### Dwengo ### @@ -20,3 +22,7 @@ DWENGO_AUTH_TEACHER_CLIENT_ID=dwengo DWENGO_AUTH_TEACHER_JWKS_ENDPOINT=http://localhost:7080/realms/teacher/protocol/openid-connect/certs DWENGO_CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000,http://localhost:9876,* + +### Advanced configuration ### + +DWENGO_LOGGING_LEVEL=debug diff --git a/backend/src/orm.ts b/backend/src/orm.ts index 76cd0ee9..1cb6babf 100644 --- a/backend/src/orm.ts +++ b/backend/src/orm.ts @@ -7,12 +7,17 @@ let orm: MikroORM | undefined; export async function initORM(testingMode = false): Promise> { const logger: Logger = getLogger(); - logger.info('Initializing ORM'); - logger.debug('MikroORM config is', config); + const options = config(testingMode); + + logger.info('MikroORM config is', options); + + logger.info('Initializing ORM'); + orm = await MikroORM.init(options); + logger.info('MikroORM initialized'); - orm = await MikroORM.init(config(testingMode)); // Update the database scheme if necessary and enabled. if (getEnvVar(envVars.DbUpdate)) { + logger.info("MikroORM: Updating database schema"); await orm.schema.updateSchema(); } else { const diff = await orm.schema.getUpdateSchemaSQL(); diff --git a/backend/tool/seed.ts b/backend/tool/seed.ts index 00e3c0bf..271bf7e0 100644 --- a/backend/tool/seed.ts +++ b/backend/tool/seed.ts @@ -77,6 +77,4 @@ export async function seedDatabase(envFile = '.env.development.local', testMode await orm.close(); } -seedDatabase().catch((err) => { - logger.error(err); -}); +seedDatabase().catch((err) => logger.error(`Seeding: ${err}`));