1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var PlatformTools_1 = require("../platform/PlatformTools");
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var FileLogger = (function () {
|
9 |
|
10 |
|
11 |
|
12 | function FileLogger(options) {
|
13 | this.options = options;
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 | |
19 |
|
20 |
|
21 | FileLogger.prototype.logQuery = function (query, parameters, queryRunner) {
|
22 | if (this.options === "all" || this.options === true || (this.options instanceof Array && this.options.indexOf("query") !== -1)) {
|
23 | var sql = query + (parameters && parameters.length ? " -- PARAMETERS: " + this.stringifyParams(parameters) : "");
|
24 | this.write("[QUERY]: " + sql);
|
25 | }
|
26 | };
|
27 | |
28 |
|
29 |
|
30 | FileLogger.prototype.logQueryError = function (error, query, parameters, queryRunner) {
|
31 | if (this.options === "all" || this.options === true || (this.options instanceof Array && this.options.indexOf("error") !== -1)) {
|
32 | var sql = query + (parameters && parameters.length ? " -- PARAMETERS: " + this.stringifyParams(parameters) : "");
|
33 | this.write([
|
34 | "[FAILED QUERY]: " + sql,
|
35 | "[QUERY ERROR]: " + error
|
36 | ]);
|
37 | }
|
38 | };
|
39 | |
40 |
|
41 |
|
42 | FileLogger.prototype.logQuerySlow = function (time, query, parameters, queryRunner) {
|
43 | var sql = query + (parameters && parameters.length ? " -- PARAMETERS: " + this.stringifyParams(parameters) : "");
|
44 | this.write("[SLOW QUERY: " + time + " ms]: " + sql);
|
45 | };
|
46 | |
47 |
|
48 |
|
49 | FileLogger.prototype.logSchemaBuild = function (message, queryRunner) {
|
50 | if (this.options === "all" || (this.options instanceof Array && this.options.indexOf("schema") !== -1)) {
|
51 | this.write(message);
|
52 | }
|
53 | };
|
54 | |
55 |
|
56 |
|
57 | FileLogger.prototype.logMigration = function (message, queryRunner) {
|
58 | this.write(message);
|
59 | };
|
60 | |
61 |
|
62 |
|
63 |
|
64 | FileLogger.prototype.log = function (level, message, queryRunner) {
|
65 | switch (level) {
|
66 | case "log":
|
67 | if (this.options === "all" || (this.options instanceof Array && this.options.indexOf("log") !== -1))
|
68 | this.write("[LOG]: " + message);
|
69 | break;
|
70 | case "info":
|
71 | if (this.options === "all" || (this.options instanceof Array && this.options.indexOf("info") !== -1))
|
72 | this.write("[INFO]: " + message);
|
73 | break;
|
74 | case "warn":
|
75 | if (this.options === "all" || (this.options instanceof Array && this.options.indexOf("warn") !== -1))
|
76 | this.write("[WARN]: " + message);
|
77 | break;
|
78 | }
|
79 | };
|
80 |
|
81 |
|
82 |
|
83 | |
84 |
|
85 |
|
86 | FileLogger.prototype.write = function (strings) {
|
87 | strings = strings instanceof Array ? strings : [strings];
|
88 | var basePath = PlatformTools_1.PlatformTools.load("app-root-path").path;
|
89 | strings = strings.map(function (str) { return "[" + new Date().toISOString() + "]" + str; });
|
90 | PlatformTools_1.PlatformTools.appendFileSync(basePath + "/ormlogs.log", strings.join("\r\n") + "\r\n");
|
91 | };
|
92 | |
93 |
|
94 |
|
95 |
|
96 | FileLogger.prototype.stringifyParams = function (parameters) {
|
97 | try {
|
98 | return JSON.stringify(parameters);
|
99 | }
|
100 | catch (error) {
|
101 | return parameters;
|
102 | }
|
103 | };
|
104 | return FileLogger;
|
105 | }());
|
106 | exports.FileLogger = FileLogger;
|
107 |
|
108 |
|