forked from nest-cloud/nestcloud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypeorm-logger.ts
30 lines (23 loc) · 1.12 KB
/
typeorm-logger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Logger } from '@nestjs/common';
import { Logger as ITypeormLogger, QueryRunner } from 'typeorm';
export class TypeormLogger implements ITypeormLogger {
private readonly logger = new Logger('TypeOrmLogger');
log(level: 'log' | 'info' | 'warn', message: any, queryRunner?: QueryRunner): any {
this.logger.log(`[${level}]:${message}`);
}
logMigration(message: string, queryRunner?: QueryRunner): any {
this.logger.debug(message);
}
logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner): any {
this.logger.debug(`${query} ${JSON.stringify(parameters)}`);
}
logQueryError(error: string, query: string, parameters?: any[], queryRunner?: QueryRunner): any {
this.logger.error(`${error} ${query} ${JSON.stringify(parameters)}`);
}
logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: QueryRunner): any {
this.logger.warn(`[Slow Query Warning] [${time}] ${query} ${JSON.stringify(parameters)}`);
}
logSchemaBuild(message: string, queryRunner?: QueryRunner): any {
this.logger.debug(message);
}
}