Add non-verbose mode for mysql query logging

This commit is contained in:
Alice Gaudon 2020-06-14 21:47:36 +02:00
parent a15d496c53
commit 362343171c
2 changed files with 12 additions and 1 deletions

View File

@ -5,13 +5,19 @@ import Log from "./models/Log";
export default class Logger {
private static logLevel: LogLevelKeys = <LogLevelKeys>config.get<string>('log_level');
private static dbLogLevel: LogLevelKeys = <LogLevelKeys>config.get<string>('db_log_level');
private static verboseMode: boolean = false;
public static verbose() {
this.verboseMode = true;
this.logLevel = <LogLevelKeys>LogLevel[LogLevel[this.logLevel] + 1] || this.logLevel;
this.dbLogLevel = <LogLevelKeys>LogLevel[LogLevel[this.dbLogLevel] + 1] || this.dbLogLevel;
Logger.info('Verbose mode');
}
public static isVerboseMode(): boolean {
return this.verboseMode;
}
public static silentError(error: Error, ...message: any[]): string {
return this.log('ERROR', message, error, true) || '';
}

View File

@ -91,7 +91,12 @@ export default class MysqlConnectionManager {
public static async query(queryString: string, values?: any, connection?: Connection): Promise<QueryResult> {
return await new Promise<QueryResult>((resolve, reject) => {
Logger.dev('Mysql query:', queryString, '; values:', values);
if (Logger.isVerboseMode()) {
Logger.dev('SQL:', queryString, '; values:', values);
} else {
Logger.dev('SQL:', queryString);
}
(connection ? connection : this.pool).query(queryString, values, (error, results, fields) => {
if (error !== null) {
reject(error);