diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 08:17:28 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 12:28:01 -0400 |
| commit | 04160af3ae807e37be65f361ad6e5012a5813820 (patch) | |
| tree | d6ee7888e21a43881a62c8929d77cb648d04b26d /packages/backend/src/postgres.ts | |
| parent | add slowQueryThreshold setting to configure slow query warning (diff) | |
| download | sharkey-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.ts | 16 |
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'], |