UNPKG

@joktec/mysql

Version:

JokTec - MySql Service

56 lines 2.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MysqlBenchmark = void 0; const helpers_1 = require("../helpers"); const mysql_config_1 = require("../mysql.config"); const mysql_exception_1 = require("../mysql.exception"); class MysqlBenchmark { constructor(benchmark, logService) { this.benchmark = benchmark; this.logService = logService; this.logService.setContext(MysqlBenchmark.name); } logQuery(query, parameters) { if (this.benchmark.enable && (this.benchmark.all || this.benchmark.level?.includes(mysql_config_1.MysqlLogLevel.query))) { const sql = (0, helpers_1.printSql)(query, parameters); this.logService.info('[SQL]: %s', sql); } } logQueryError(error, query, parameters) { if (this.benchmark.enable && (this.benchmark.all || this.benchmark.level?.includes(mysql_config_1.MysqlLogLevel.error))) { const _error = error instanceof Error ? error : new mysql_exception_1.MysqlException(error); const sql = (0, helpers_1.printSql)(query, parameters); this.logService.error(_error, `[FAILED QUERY]: %s`, sql); } } logQuerySlow(time, query, parameters) { const sql = (0, helpers_1.printSql)(query, parameters); this.logService.warn('[SLOW QUERY: %s ms]: %s', time, sql); } logSchemaBuild(message) { if (this.benchmark.all && this.benchmark.level?.includes(mysql_config_1.MysqlLogLevel.schema)) { this.logService.trace(message); } } logMigration(message) { this.logService.trace(message); } log(level, message) { switch (level) { case 'log': if (this.benchmark.all && this.benchmark.level?.includes(mysql_config_1.MysqlLogLevel.log)) this.logService.debug('[LOG]: %s', message); break; case 'info': if (this.benchmark.all && this.benchmark.level?.includes(mysql_config_1.MysqlLogLevel.info)) this.logService.info('[INFO]: %s', message); break; case 'warn': if (this.benchmark.all && this.benchmark.level?.includes(mysql_config_1.MysqlLogLevel.warn)) this.logService.warn('[WARN]: %s', message); break; } } } exports.MysqlBenchmark = MysqlBenchmark; //# sourceMappingURL=mysql.benchmark.js.map