UNPKG

3.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4var debug_1 = tslib_1.__importDefault(require("debug"));
5var PlatformTools_1 = require("../platform/PlatformTools");
6/**
7 * Performs logging of the events in TypeORM via debug library.
8 */
9var DebugLogger = /** @class */ (function () {
10 function DebugLogger() {
11 this.debugQueryLog = debug_1.default("typeorm:query:log");
12 this.debugQueryError = debug_1.default("typeorm:query:error");
13 this.debugQuerySlow = debug_1.default("typeorm:query:slow");
14 this.debugSchemaBuild = debug_1.default("typeorm:schema");
15 this.debugMigration = debug_1.default("typeorm:migration");
16 this.debugLog = debug_1.default("typeorm:log");
17 this.debugInfo = debug_1.default("typeorm:info");
18 this.debugWarn = debug_1.default("typeorm:warn");
19 }
20 /**
21 * Logs query and parameters used in it.
22 */
23 DebugLogger.prototype.logQuery = function (query, parameters, queryRunner) {
24 if (this.debugQueryLog.enabled) {
25 this.debugQueryLog(PlatformTools_1.PlatformTools.highlightSql(query) + ";");
26 if (parameters && parameters.length) {
27 this.debugQueryLog("parameters:", parameters);
28 }
29 }
30 };
31 /**
32 * Logs query that failed.
33 */
34 DebugLogger.prototype.logQueryError = function (error, query, parameters, queryRunner) {
35 if (this.debugQueryError.enabled) {
36 this.debugQueryError(PlatformTools_1.PlatformTools.highlightSql(query) + ";");
37 if (parameters && parameters.length) {
38 this.debugQueryError("parameters:", parameters);
39 }
40 this.debugQueryError("error: ", error);
41 }
42 };
43 /**
44 * Logs query that is slow.
45 */
46 DebugLogger.prototype.logQuerySlow = function (time, query, parameters, queryRunner) {
47 if (this.debugQuerySlow.enabled) {
48 this.debugQuerySlow(PlatformTools_1.PlatformTools.highlightSql(query) + ";");
49 if (parameters && parameters.length) {
50 this.debugQuerySlow("parameters:", parameters);
51 }
52 this.debugQuerySlow("execution time:", time);
53 }
54 };
55 /**
56 * Logs events from the schema build process.
57 */
58 DebugLogger.prototype.logSchemaBuild = function (message, queryRunner) {
59 if (this.debugSchemaBuild.enabled) {
60 this.debugSchemaBuild(message);
61 }
62 };
63 /**
64 * Logs events from the migration run process.
65 */
66 DebugLogger.prototype.logMigration = function (message, queryRunner) {
67 if (this.debugMigration.enabled) {
68 this.debugMigration(message);
69 }
70 };
71 /**
72 * Perform logging using given logger.
73 * Log has its own level and message.
74 */
75 DebugLogger.prototype.log = function (level, message, queryRunner) {
76 switch (level) {
77 case "log":
78 if (this.debugLog.enabled) {
79 this.debugLog(message);
80 }
81 break;
82 case "info":
83 if (this.debugInfo.enabled) {
84 this.debugInfo(message);
85 }
86 break;
87 case "warn":
88 if (this.debugWarn.enabled) {
89 this.debugWarn(message);
90 }
91 break;
92 }
93 };
94 return DebugLogger;
95}());
96exports.DebugLogger = DebugLogger;
97
98//# sourceMappingURL=DebugLogger.js.map