summaryrefslogtreecommitdiff
path: root/packages/backend/src/postgres.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-30 08:17:28 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-05-30 12:28:01 -0400
commit04160af3ae807e37be65f361ad6e5012a5813820 (patch)
treed6ee7888e21a43881a62c8929d77cb648d04b26d /packages/backend/src/postgres.ts
parentadd slowQueryThreshold setting to configure slow query warning (diff)
downloadsharkey-04160af3ae807e37be65f361ad6e5012a5813820.tar.gz
sharkey-04160af3ae807e37be65f361ad6e5012a5813820.tar.bz2
sharkey-04160af3ae807e37be65f361ad6e5012a5813820.zip
fix TypeORM logging to native console instead of NestJS logger
Diffstat (limited to 'packages/backend/src/postgres.ts')
-rw-r--r--packages/backend/src/postgres.ts16
1 files changed, 9 insertions, 7 deletions
diff --git a/packages/backend/src/postgres.ts b/packages/backend/src/postgres.ts
index eed60dd499..eef11d1ed8 100644
--- a/packages/backend/src/postgres.ts
+++ b/packages/backend/src/postgres.ts
@@ -101,6 +101,7 @@ const sqlLogger = dbLogger.createSubLogger('sql', 'gray');
export type LoggerProps = {
disableQueryTruncation?: boolean;
+ enableQueryLogging?: boolean;
enableQueryParamLogging?: boolean;
printReplicationMode?: boolean,
};
@@ -150,6 +151,8 @@ class MyCustomLogger implements Logger {
@bindThis
public logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner) {
+ if (!this.props.enableQueryLogging) return;
+
const prefix = (this.props.printReplicationMode && queryRunner)
? `[${queryRunner.getReplicationMode()}] `
: undefined;
@@ -314,13 +317,12 @@ export function createPostgresDataSource(config: Config) {
},
} : false,
logging: log,
- logger: log
- ? new MyCustomLogger({
- disableQueryTruncation: config.logging?.sql?.disableQueryTruncation,
- enableQueryParamLogging: config.logging?.sql?.enableQueryParamLogging,
- printReplicationMode: !!config.dbReplications,
- })
- : undefined,
+ logger: new MyCustomLogger({
+ disableQueryTruncation: config.logging?.sql?.disableQueryTruncation,
+ enableQueryLogging: log,
+ enableQueryParamLogging: config.logging?.sql?.enableQueryParamLogging,
+ printReplicationMode: !!config.dbReplications,
+ }),
maxQueryExecutionTime: config.db.slowQueryThreshold,
entities: entities,
migrations: ['../../migration/*.js'],