1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const level_1 = require("./level");
|
4 | const display_1 = require("./display");
|
5 | const include_1 = require("./include");
|
6 | class Logger {
|
7 | constructor(name, color, developmentMode, allowed, isMuted, fixedWidth, display) {
|
8 | this.name = name;
|
9 | this.color = color;
|
10 | this.developmentMode = developmentMode;
|
11 | this.allowed = allowed;
|
12 | this.isMuted = isMuted;
|
13 | this.fixedWidth = fixedWidth;
|
14 | this.display = display;
|
15 | |
16 |
|
17 |
|
18 | this.d = (name, ...data) => this._data(name, data);
|
19 | |
20 |
|
21 |
|
22 | this.er = (name, ...data) => this._error(name, data);
|
23 | |
24 |
|
25 |
|
26 | this.i = (name, ...data) => this._info(name, data);
|
27 | |
28 |
|
29 |
|
30 | this.w = (name, ...data) => this._warn(name, data);
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 | this.data = (message, ...otherParams) => { return this._data(message, otherParams); };
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 | this.error = (message, ...otherParams) => this._error(message, otherParams);
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 | this.info = (message, ...otherParams) => this._info(message, otherParams);
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 | this.warn = (message, ...otherParams) => this._warn(message, otherParams);
|
55 | }
|
56 | _data(name, ...data) {
|
57 | if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
|
58 | && !include_1.contain(this.allowed, level_1.Level.DATA))
|
59 | return this;
|
60 | if (Logger.isProductionMode)
|
61 | return this;
|
62 | if (this.display !== undefined)
|
63 | this.display(name, data, level_1.Level.DATA, this.name);
|
64 | else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.DATA)) {
|
65 | display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.DATA, this.fixedWidth]);
|
66 | }
|
67 | return this;
|
68 | }
|
69 | _error(name, ...data) {
|
70 | if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
|
71 | && !include_1.contain(this.allowed, level_1.Level.ERROR))
|
72 | return this;
|
73 | if (Logger.isProductionMode)
|
74 | return this;
|
75 | if (this.display !== undefined)
|
76 | this.display(name, data, level_1.Level.ERROR, this.name);
|
77 | else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.ERROR)) {
|
78 | display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.ERROR, this.fixedWidth]);
|
79 | }
|
80 | return this;
|
81 | }
|
82 | _info(name, ...data) {
|
83 | if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
|
84 | && !include_1.contain(this.allowed, level_1.Level.INFO))
|
85 | return this;
|
86 | if (Logger.isProductionMode)
|
87 | return this;
|
88 | if (this.display !== undefined)
|
89 | this.display(name, data, level_1.Level.INFO, this.name);
|
90 | else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.INFO)) {
|
91 | display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.INFO, this.fixedWidth]);
|
92 | }
|
93 | return this;
|
94 | }
|
95 | _warn(name, ...data) {
|
96 | if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING)
|
97 | && !include_1.contain(this.allowed, level_1.Level.WARN))
|
98 | return this;
|
99 | if (Logger.isProductionMode)
|
100 | return this;
|
101 | if (this.display !== undefined)
|
102 | this.display(name, data, level_1.Level.WARN, this.name);
|
103 | else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.WARN)) {
|
104 | display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.WARN, this.fixedWidth]);
|
105 | }
|
106 | return this;
|
107 | }
|
108 | _logMessage(name, level, ...data) {
|
109 | if (this.isMuted)
|
110 | return this;
|
111 | if (this.allowed.length >= 1 && include_1.contain(this.allowed, level)
|
112 | && !include_1.contain(this.allowed, level))
|
113 | return this;
|
114 | if (Logger.isProductionMode)
|
115 | return this;
|
116 | if (this.display !== undefined)
|
117 | this.display(name, data, level, this.name);
|
118 | else if (this.allowed.length === 0 || include_1.contain(this.allowed, level)) {
|
119 | display_1.Display.msg(name, data, this.name, this.color, level, this.fixedWidth);
|
120 | }
|
121 | return this;
|
122 | }
|
123 | level(l) {
|
124 | this._level = l;
|
125 | return this;
|
126 | }
|
127 | mute() {
|
128 | this.isMuted = true;
|
129 | }
|
130 | }
|
131 | Logger.isProductionMode = false;
|
132 | exports.Logger = Logger;
|
133 |
|
\ | No newline at end of file |