Add non-verbose mode for mysql query logging
This commit is contained in:
parent
a15d496c53
commit
362343171c
@ -5,13 +5,19 @@ import Log from "./models/Log";
|
|||||||
export default class Logger {
|
export default class Logger {
|
||||||
private static logLevel: LogLevelKeys = <LogLevelKeys>config.get<string>('log_level');
|
private static logLevel: LogLevelKeys = <LogLevelKeys>config.get<string>('log_level');
|
||||||
private static dbLogLevel: LogLevelKeys = <LogLevelKeys>config.get<string>('db_log_level');
|
private static dbLogLevel: LogLevelKeys = <LogLevelKeys>config.get<string>('db_log_level');
|
||||||
|
private static verboseMode: boolean = false;
|
||||||
|
|
||||||
public static verbose() {
|
public static verbose() {
|
||||||
|
this.verboseMode = true;
|
||||||
this.logLevel = <LogLevelKeys>LogLevel[LogLevel[this.logLevel] + 1] || this.logLevel;
|
this.logLevel = <LogLevelKeys>LogLevel[LogLevel[this.logLevel] + 1] || this.logLevel;
|
||||||
this.dbLogLevel = <LogLevelKeys>LogLevel[LogLevel[this.dbLogLevel] + 1] || this.dbLogLevel;
|
this.dbLogLevel = <LogLevelKeys>LogLevel[LogLevel[this.dbLogLevel] + 1] || this.dbLogLevel;
|
||||||
Logger.info('Verbose mode');
|
Logger.info('Verbose mode');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static isVerboseMode(): boolean {
|
||||||
|
return this.verboseMode;
|
||||||
|
}
|
||||||
|
|
||||||
public static silentError(error: Error, ...message: any[]): string {
|
public static silentError(error: Error, ...message: any[]): string {
|
||||||
return this.log('ERROR', message, error, true) || '';
|
return this.log('ERROR', message, error, true) || '';
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,12 @@ export default class MysqlConnectionManager {
|
|||||||
|
|
||||||
public static async query(queryString: string, values?: any, connection?: Connection): Promise<QueryResult> {
|
public static async query(queryString: string, values?: any, connection?: Connection): Promise<QueryResult> {
|
||||||
return await new Promise<QueryResult>((resolve, reject) => {
|
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) => {
|
(connection ? connection : this.pool).query(queryString, values, (error, results, fields) => {
|
||||||
if (error !== null) {
|
if (error !== null) {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
Loading…
Reference in New Issue
Block a user