From 05a3dfa26d44dde6b3918f36314ce557316488ad Mon Sep 17 00:00:00 2001 From: Philip Okugbe <16838612+Philipinho@users.noreply.github.com> Date: Fri, 7 Mar 2025 00:06:25 +0000 Subject: [PATCH] Option to log db queries in dev mode (#827) --- apps/server/src/database/database.module.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/server/src/database/database.module.ts b/apps/server/src/database/database.module.ts index ff389763..d1f8366e 100644 --- a/apps/server/src/database/database.module.ts +++ b/apps/server/src/database/database.module.ts @@ -46,12 +46,15 @@ types.setTypeParser(types.builtins.INT8, (val) => Number(val)); plugins: [new CamelCasePlugin()], log: (event: LogEvent) => { if (environmentService.getNodeEnv() !== 'development') return; + const logger = new Logger(DatabaseModule.name); if (event.level === 'query') { - // console.log(event.query.sql); - //if (event.query.parameters.length > 0) { - //console.log('parameters: ' + event.query.parameters); - //} - // console.log('time: ' + event.queryDurationMillis); + if (process.env.DEBUG_DB?.toLowerCase() === 'true') { + logger.debug(event.query.sql); + logger.debug('query time: ' + event.queryDurationMillis + ' ms'); + //if (event.query.parameters.length > 0) { + // logger.debug('parameters: ' + event.query.parameters); + //} + } } }, }),