@rabbit-company/logger 2.1.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src → browser}/logger.d.ts +26 -32
- package/browser/logger.js +500 -0
- package/module/logger.d.ts +26 -32
- package/module/logger.js +261 -272
- package/package.json +12 -9
- package/src/logger.js +0 -210
|
@@ -1,100 +1,94 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents a logger utility for logging messages with different log levels.
|
|
3
|
-
|
|
3
|
+
*/
|
|
4
4
|
export default class Logger {
|
|
5
|
-
static
|
|
5
|
+
private static NDJsonData;
|
|
6
6
|
/**
|
|
7
7
|
* Indicates whether NDJson is enabled.
|
|
8
8
|
* @type {boolean}
|
|
9
|
-
|
|
9
|
+
*/
|
|
10
10
|
static NDJson: boolean;
|
|
11
11
|
/**
|
|
12
12
|
* The log level of the logger.
|
|
13
13
|
* @type {number}
|
|
14
|
-
|
|
14
|
+
*/
|
|
15
15
|
static level: number;
|
|
16
16
|
/**
|
|
17
17
|
* Indicates whether colors are enabled for log messages.
|
|
18
18
|
* @type {boolean}
|
|
19
|
-
|
|
19
|
+
*/
|
|
20
20
|
static colors: boolean;
|
|
21
21
|
/**
|
|
22
22
|
* Defines log levels and their associated numeric values.
|
|
23
|
-
* @type {
|
|
24
|
-
|
|
25
|
-
static levels:
|
|
26
|
-
static
|
|
27
|
-
0: string;
|
|
28
|
-
1: string;
|
|
29
|
-
2: string;
|
|
30
|
-
3: string;
|
|
31
|
-
4: string;
|
|
32
|
-
5: string;
|
|
33
|
-
6: string;
|
|
34
|
-
};
|
|
23
|
+
* @type {Record<string, number>}
|
|
24
|
+
*/
|
|
25
|
+
static readonly levels: Record<string, number>;
|
|
26
|
+
private static readonly levelsRev;
|
|
35
27
|
/**
|
|
36
28
|
* Parses the log message to ensure it is a string.
|
|
37
29
|
* @param {*} message - The log message.
|
|
38
30
|
* @returns {string | null} - The parsed log message or null if the message is undefined.
|
|
39
|
-
|
|
31
|
+
*/
|
|
40
32
|
static parseMessage(message: any): string | null;
|
|
41
33
|
/**
|
|
42
34
|
* Formats the log message with timestamp and log level.
|
|
43
35
|
* @param {string} message - The log message.
|
|
44
36
|
* @param {number} logLevel - The log level.
|
|
45
37
|
* @returns {string} - The formatted log message.
|
|
46
|
-
|
|
38
|
+
*/
|
|
47
39
|
static formatMessage(message: string, logLevel: number): string;
|
|
48
40
|
/**
|
|
49
41
|
* Processes and logs a message with the specified log level.
|
|
50
42
|
* @param {*} message - The log message.
|
|
51
|
-
* @param {number}
|
|
52
|
-
|
|
53
|
-
static
|
|
43
|
+
* @param {number} logLevel - The log level.
|
|
44
|
+
*/
|
|
45
|
+
private static processMessage;
|
|
54
46
|
/**
|
|
55
47
|
* Logs an error message.
|
|
56
48
|
* @param {*} message - The error message.
|
|
57
|
-
|
|
49
|
+
*/
|
|
58
50
|
static error(message: any): void;
|
|
59
51
|
/**
|
|
60
52
|
* Logs a warning message.
|
|
61
53
|
* @param {*} message - The warning message.
|
|
62
|
-
|
|
54
|
+
*/
|
|
63
55
|
static warn(message: any): void;
|
|
64
56
|
/**
|
|
65
57
|
* Logs an informational message.
|
|
66
58
|
* @param {*} message - The informational message.
|
|
67
|
-
|
|
59
|
+
*/
|
|
68
60
|
static info(message: any): void;
|
|
69
61
|
/**
|
|
70
62
|
* Logs an HTTP-related message.
|
|
71
63
|
* @param {*} message - The HTTP-related message.
|
|
72
|
-
|
|
64
|
+
*/
|
|
73
65
|
static http(message: any): void;
|
|
74
66
|
/**
|
|
75
67
|
* Logs a verbose message.
|
|
76
68
|
* @param {*} message - The verbose message.
|
|
77
|
-
|
|
69
|
+
*/
|
|
78
70
|
static verbose(message: any): void;
|
|
79
71
|
/**
|
|
80
72
|
* Logs a debug message.
|
|
81
73
|
* @param {*} message - The debug message.
|
|
82
|
-
|
|
74
|
+
*/
|
|
83
75
|
static debug(message: any): void;
|
|
84
76
|
/**
|
|
85
77
|
* Logs a silly message.
|
|
86
78
|
* @param {*} message - The silly message.
|
|
87
|
-
|
|
79
|
+
*/
|
|
88
80
|
static silly(message: any): void;
|
|
89
81
|
/**
|
|
90
82
|
* Appends a message to NDJson format.
|
|
91
83
|
* @param {string} message - The message to append.
|
|
92
84
|
* @param {number} logLevel - The log level associated with the message.
|
|
93
|
-
|
|
85
|
+
*/
|
|
94
86
|
static putNDJson(message: string, logLevel: number): void;
|
|
95
87
|
/**
|
|
96
88
|
* Gets the NDJson log.
|
|
97
89
|
* @returns {string} - The NDJson log.
|
|
98
|
-
|
|
90
|
+
*/
|
|
99
91
|
static getNDJson(): string;
|
|
100
|
-
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
// node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
2
|
+
var assembleStyles = function() {
|
|
3
|
+
const codes = new Map;
|
|
4
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
5
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
6
|
+
styles[styleName] = {
|
|
7
|
+
open: `\x1B[${style[0]}m`,
|
|
8
|
+
close: `\x1B[${style[1]}m`
|
|
9
|
+
};
|
|
10
|
+
group[styleName] = styles[styleName];
|
|
11
|
+
codes.set(style[0], style[1]);
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(styles, groupName, {
|
|
14
|
+
value: group,
|
|
15
|
+
enumerable: false
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(styles, "codes", {
|
|
19
|
+
value: codes,
|
|
20
|
+
enumerable: false
|
|
21
|
+
});
|
|
22
|
+
styles.color.close = "\x1B[39m";
|
|
23
|
+
styles.bgColor.close = "\x1B[49m";
|
|
24
|
+
styles.color.ansi = wrapAnsi16();
|
|
25
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
26
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
27
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
28
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
29
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
30
|
+
Object.defineProperties(styles, {
|
|
31
|
+
rgbToAnsi256: {
|
|
32
|
+
value(red, green, blue) {
|
|
33
|
+
if (red === green && green === blue) {
|
|
34
|
+
if (red < 8) {
|
|
35
|
+
return 16;
|
|
36
|
+
}
|
|
37
|
+
if (red > 248) {
|
|
38
|
+
return 231;
|
|
39
|
+
}
|
|
40
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
41
|
+
}
|
|
42
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
43
|
+
},
|
|
44
|
+
enumerable: false
|
|
45
|
+
},
|
|
46
|
+
hexToRgb: {
|
|
47
|
+
value(hex) {
|
|
48
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
49
|
+
if (!matches) {
|
|
50
|
+
return [0, 0, 0];
|
|
51
|
+
}
|
|
52
|
+
let [colorString] = matches;
|
|
53
|
+
if (colorString.length === 3) {
|
|
54
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
55
|
+
}
|
|
56
|
+
const integer = Number.parseInt(colorString, 16);
|
|
57
|
+
return [
|
|
58
|
+
integer >> 16 & 255,
|
|
59
|
+
integer >> 8 & 255,
|
|
60
|
+
integer & 255
|
|
61
|
+
];
|
|
62
|
+
},
|
|
63
|
+
enumerable: false
|
|
64
|
+
},
|
|
65
|
+
hexToAnsi256: {
|
|
66
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
67
|
+
enumerable: false
|
|
68
|
+
},
|
|
69
|
+
ansi256ToAnsi: {
|
|
70
|
+
value(code) {
|
|
71
|
+
if (code < 8) {
|
|
72
|
+
return 30 + code;
|
|
73
|
+
}
|
|
74
|
+
if (code < 16) {
|
|
75
|
+
return 90 + (code - 8);
|
|
76
|
+
}
|
|
77
|
+
let red;
|
|
78
|
+
let green;
|
|
79
|
+
let blue;
|
|
80
|
+
if (code >= 232) {
|
|
81
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
82
|
+
green = red;
|
|
83
|
+
blue = red;
|
|
84
|
+
} else {
|
|
85
|
+
code -= 16;
|
|
86
|
+
const remainder = code % 36;
|
|
87
|
+
red = Math.floor(code / 36) / 5;
|
|
88
|
+
green = Math.floor(remainder / 6) / 5;
|
|
89
|
+
blue = remainder % 6 / 5;
|
|
90
|
+
}
|
|
91
|
+
const value = Math.max(red, green, blue) * 2;
|
|
92
|
+
if (value === 0) {
|
|
93
|
+
return 30;
|
|
94
|
+
}
|
|
95
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
96
|
+
if (value === 2) {
|
|
97
|
+
result += 60;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
},
|
|
101
|
+
enumerable: false
|
|
102
|
+
},
|
|
103
|
+
rgbToAnsi: {
|
|
104
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
105
|
+
enumerable: false
|
|
106
|
+
},
|
|
107
|
+
hexToAnsi: {
|
|
108
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
109
|
+
enumerable: false
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return styles;
|
|
113
|
+
};
|
|
114
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
115
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
116
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
117
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
118
|
+
var styles = {
|
|
119
|
+
modifier: {
|
|
120
|
+
reset: [0, 0],
|
|
121
|
+
bold: [1, 22],
|
|
122
|
+
dim: [2, 22],
|
|
123
|
+
italic: [3, 23],
|
|
124
|
+
underline: [4, 24],
|
|
125
|
+
overline: [53, 55],
|
|
126
|
+
inverse: [7, 27],
|
|
127
|
+
hidden: [8, 28],
|
|
128
|
+
strikethrough: [9, 29]
|
|
129
|
+
},
|
|
130
|
+
color: {
|
|
131
|
+
black: [30, 39],
|
|
132
|
+
red: [31, 39],
|
|
133
|
+
green: [32, 39],
|
|
134
|
+
yellow: [33, 39],
|
|
135
|
+
blue: [34, 39],
|
|
136
|
+
magenta: [35, 39],
|
|
137
|
+
cyan: [36, 39],
|
|
138
|
+
white: [37, 39],
|
|
139
|
+
blackBright: [90, 39],
|
|
140
|
+
gray: [90, 39],
|
|
141
|
+
grey: [90, 39],
|
|
142
|
+
redBright: [91, 39],
|
|
143
|
+
greenBright: [92, 39],
|
|
144
|
+
yellowBright: [93, 39],
|
|
145
|
+
blueBright: [94, 39],
|
|
146
|
+
magentaBright: [95, 39],
|
|
147
|
+
cyanBright: [96, 39],
|
|
148
|
+
whiteBright: [97, 39]
|
|
149
|
+
},
|
|
150
|
+
bgColor: {
|
|
151
|
+
bgBlack: [40, 49],
|
|
152
|
+
bgRed: [41, 49],
|
|
153
|
+
bgGreen: [42, 49],
|
|
154
|
+
bgYellow: [43, 49],
|
|
155
|
+
bgBlue: [44, 49],
|
|
156
|
+
bgMagenta: [45, 49],
|
|
157
|
+
bgCyan: [46, 49],
|
|
158
|
+
bgWhite: [47, 49],
|
|
159
|
+
bgBlackBright: [100, 49],
|
|
160
|
+
bgGray: [100, 49],
|
|
161
|
+
bgGrey: [100, 49],
|
|
162
|
+
bgRedBright: [101, 49],
|
|
163
|
+
bgGreenBright: [102, 49],
|
|
164
|
+
bgYellowBright: [103, 49],
|
|
165
|
+
bgBlueBright: [104, 49],
|
|
166
|
+
bgMagentaBright: [105, 49],
|
|
167
|
+
bgCyanBright: [106, 49],
|
|
168
|
+
bgWhiteBright: [107, 49]
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
172
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
173
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
174
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
175
|
+
var ansiStyles = assembleStyles();
|
|
176
|
+
var ansi_styles_default = ansiStyles;
|
|
177
|
+
|
|
178
|
+
// node_modules/chalk/source/vendor/supports-color/browser.js
|
|
179
|
+
var level = (() => {
|
|
180
|
+
if (navigator.userAgentData) {
|
|
181
|
+
const brand = navigator.userAgentData.brands.find(({ brand: brand2 }) => brand2 === "Chromium");
|
|
182
|
+
if (brand && brand.version > 93) {
|
|
183
|
+
return 3;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) {
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
return 0;
|
|
190
|
+
})();
|
|
191
|
+
var colorSupport = level !== 0 && {
|
|
192
|
+
level,
|
|
193
|
+
hasBasic: true,
|
|
194
|
+
has256: level >= 2,
|
|
195
|
+
has16m: level >= 3
|
|
196
|
+
};
|
|
197
|
+
var supportsColor = {
|
|
198
|
+
stdout: colorSupport,
|
|
199
|
+
stderr: colorSupport
|
|
200
|
+
};
|
|
201
|
+
var browser_default = supportsColor;
|
|
202
|
+
|
|
203
|
+
// node_modules/chalk/source/utilities.js
|
|
204
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
205
|
+
let index = string.indexOf(substring);
|
|
206
|
+
if (index === -1) {
|
|
207
|
+
return string;
|
|
208
|
+
}
|
|
209
|
+
const substringLength = substring.length;
|
|
210
|
+
let endIndex = 0;
|
|
211
|
+
let returnValue = "";
|
|
212
|
+
do {
|
|
213
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
214
|
+
endIndex = index + substringLength;
|
|
215
|
+
index = string.indexOf(substring, endIndex);
|
|
216
|
+
} while (index !== -1);
|
|
217
|
+
returnValue += string.slice(endIndex);
|
|
218
|
+
return returnValue;
|
|
219
|
+
}
|
|
220
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
221
|
+
let endIndex = 0;
|
|
222
|
+
let returnValue = "";
|
|
223
|
+
do {
|
|
224
|
+
const gotCR = string[index - 1] === "\r";
|
|
225
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
226
|
+
endIndex = index + 1;
|
|
227
|
+
index = string.indexOf("\n", endIndex);
|
|
228
|
+
} while (index !== -1);
|
|
229
|
+
returnValue += string.slice(endIndex);
|
|
230
|
+
return returnValue;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// node_modules/chalk/source/index.js
|
|
234
|
+
var createChalk = function(options) {
|
|
235
|
+
return chalkFactory(options);
|
|
236
|
+
};
|
|
237
|
+
var { stdout: stdoutColor, stderr: stderrColor } = browser_default;
|
|
238
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
239
|
+
var STYLER = Symbol("STYLER");
|
|
240
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
241
|
+
var levelMapping = [
|
|
242
|
+
"ansi",
|
|
243
|
+
"ansi",
|
|
244
|
+
"ansi256",
|
|
245
|
+
"ansi16m"
|
|
246
|
+
];
|
|
247
|
+
var styles2 = Object.create(null);
|
|
248
|
+
var applyOptions = (object, options = {}) => {
|
|
249
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
250
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
251
|
+
}
|
|
252
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
253
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
254
|
+
};
|
|
255
|
+
var chalkFactory = (options) => {
|
|
256
|
+
const chalk = (...strings) => strings.join(" ");
|
|
257
|
+
applyOptions(chalk, options);
|
|
258
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
259
|
+
return chalk;
|
|
260
|
+
};
|
|
261
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
262
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
263
|
+
styles2[styleName] = {
|
|
264
|
+
get() {
|
|
265
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
266
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
267
|
+
return builder;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
styles2.visible = {
|
|
272
|
+
get() {
|
|
273
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
274
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
275
|
+
return builder;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
var getModelAnsi = (model, level2, type, ...arguments_) => {
|
|
279
|
+
if (model === "rgb") {
|
|
280
|
+
if (level2 === "ansi16m") {
|
|
281
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
282
|
+
}
|
|
283
|
+
if (level2 === "ansi256") {
|
|
284
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
285
|
+
}
|
|
286
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
287
|
+
}
|
|
288
|
+
if (model === "hex") {
|
|
289
|
+
return getModelAnsi("rgb", level2, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
290
|
+
}
|
|
291
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
292
|
+
};
|
|
293
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
294
|
+
for (const model of usedModels) {
|
|
295
|
+
styles2[model] = {
|
|
296
|
+
get() {
|
|
297
|
+
const { level: level2 } = this;
|
|
298
|
+
return function(...arguments_) {
|
|
299
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level2], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
300
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
305
|
+
styles2[bgModel] = {
|
|
306
|
+
get() {
|
|
307
|
+
const { level: level2 } = this;
|
|
308
|
+
return function(...arguments_) {
|
|
309
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level2], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
310
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
var proto = Object.defineProperties(() => {
|
|
316
|
+
}, {
|
|
317
|
+
...styles2,
|
|
318
|
+
level: {
|
|
319
|
+
enumerable: true,
|
|
320
|
+
get() {
|
|
321
|
+
return this[GENERATOR].level;
|
|
322
|
+
},
|
|
323
|
+
set(level2) {
|
|
324
|
+
this[GENERATOR].level = level2;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
var createStyler = (open, close, parent) => {
|
|
329
|
+
let openAll;
|
|
330
|
+
let closeAll;
|
|
331
|
+
if (parent === undefined) {
|
|
332
|
+
openAll = open;
|
|
333
|
+
closeAll = close;
|
|
334
|
+
} else {
|
|
335
|
+
openAll = parent.openAll + open;
|
|
336
|
+
closeAll = close + parent.closeAll;
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
open,
|
|
340
|
+
close,
|
|
341
|
+
openAll,
|
|
342
|
+
closeAll,
|
|
343
|
+
parent
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
347
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
348
|
+
Object.setPrototypeOf(builder, proto);
|
|
349
|
+
builder[GENERATOR] = self;
|
|
350
|
+
builder[STYLER] = _styler;
|
|
351
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
352
|
+
return builder;
|
|
353
|
+
};
|
|
354
|
+
var applyStyle = (self, string) => {
|
|
355
|
+
if (self.level <= 0 || !string) {
|
|
356
|
+
return self[IS_EMPTY] ? "" : string;
|
|
357
|
+
}
|
|
358
|
+
let styler = self[STYLER];
|
|
359
|
+
if (styler === undefined) {
|
|
360
|
+
return string;
|
|
361
|
+
}
|
|
362
|
+
const { openAll, closeAll } = styler;
|
|
363
|
+
if (string.includes("\x1B")) {
|
|
364
|
+
while (styler !== undefined) {
|
|
365
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
366
|
+
styler = styler.parent;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const lfIndex = string.indexOf("\n");
|
|
370
|
+
if (lfIndex !== -1) {
|
|
371
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
372
|
+
}
|
|
373
|
+
return openAll + string + closeAll;
|
|
374
|
+
};
|
|
375
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
376
|
+
var chalk = createChalk();
|
|
377
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
378
|
+
var source_default = chalk;
|
|
379
|
+
|
|
380
|
+
// src/logger.ts
|
|
381
|
+
class Logger {
|
|
382
|
+
static NDJsonData = "";
|
|
383
|
+
static NDJson = false;
|
|
384
|
+
static level = 2;
|
|
385
|
+
static colors = true;
|
|
386
|
+
static levels = {
|
|
387
|
+
error: 0,
|
|
388
|
+
warn: 1,
|
|
389
|
+
info: 2,
|
|
390
|
+
http: 3,
|
|
391
|
+
verbose: 4,
|
|
392
|
+
debug: 5,
|
|
393
|
+
silly: 6
|
|
394
|
+
};
|
|
395
|
+
static levelsRev = {
|
|
396
|
+
0: "ERROR",
|
|
397
|
+
1: "WARN",
|
|
398
|
+
2: "INFO",
|
|
399
|
+
3: "HTTP",
|
|
400
|
+
4: "VERBOSE",
|
|
401
|
+
5: "DEBUG",
|
|
402
|
+
6: "SILLY"
|
|
403
|
+
};
|
|
404
|
+
static parseMessage(message) {
|
|
405
|
+
if (typeof message === "undefined")
|
|
406
|
+
return null;
|
|
407
|
+
if (typeof message === "object")
|
|
408
|
+
message = JSON.stringify(message);
|
|
409
|
+
return message;
|
|
410
|
+
}
|
|
411
|
+
static formatMessage(message, logLevel) {
|
|
412
|
+
let type = this.levelsRev[logLevel];
|
|
413
|
+
let date = new Date().toISOString().split(".")[0].replace("T", " ");
|
|
414
|
+
if (this.colors) {
|
|
415
|
+
date = source_default.gray(date);
|
|
416
|
+
switch (logLevel) {
|
|
417
|
+
case 0:
|
|
418
|
+
type = source_default.bold(source_default.red(type));
|
|
419
|
+
message = source_default.red(message);
|
|
420
|
+
break;
|
|
421
|
+
case 1:
|
|
422
|
+
type = source_default.bold(source_default.yellow(type));
|
|
423
|
+
message = source_default.yellow(message);
|
|
424
|
+
break;
|
|
425
|
+
case 2:
|
|
426
|
+
type = source_default.bold(source_default.cyan(type));
|
|
427
|
+
message = source_default.cyan(message);
|
|
428
|
+
break;
|
|
429
|
+
case 3:
|
|
430
|
+
type = source_default.bold(source_default.blue(type));
|
|
431
|
+
message = source_default.blue(message);
|
|
432
|
+
break;
|
|
433
|
+
case 4:
|
|
434
|
+
type = source_default.bold(source_default.blue(type));
|
|
435
|
+
message = source_default.blue(message);
|
|
436
|
+
break;
|
|
437
|
+
case 5:
|
|
438
|
+
type = source_default.bold(source_default.gray(type));
|
|
439
|
+
message = source_default.gray(message);
|
|
440
|
+
break;
|
|
441
|
+
case 6:
|
|
442
|
+
type = source_default.bold(source_default.gray(type));
|
|
443
|
+
message = source_default.gray(message);
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return `[${date}] ${type} ${message}`;
|
|
448
|
+
}
|
|
449
|
+
static processMessage(message, logLevel) {
|
|
450
|
+
if (this.level < logLevel)
|
|
451
|
+
return;
|
|
452
|
+
message = this.parseMessage(message);
|
|
453
|
+
if (message === null)
|
|
454
|
+
return;
|
|
455
|
+
if (this.NDJson)
|
|
456
|
+
this.putNDJson(message, logLevel);
|
|
457
|
+
switch (logLevel) {
|
|
458
|
+
case 0:
|
|
459
|
+
console.error(this.formatMessage(message, logLevel));
|
|
460
|
+
break;
|
|
461
|
+
case 1:
|
|
462
|
+
console.warn(this.formatMessage(message, logLevel));
|
|
463
|
+
break;
|
|
464
|
+
default:
|
|
465
|
+
console.info(this.formatMessage(message, logLevel));
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
static error(message) {
|
|
470
|
+
this.processMessage(message, 0);
|
|
471
|
+
}
|
|
472
|
+
static warn(message) {
|
|
473
|
+
this.processMessage(message, 1);
|
|
474
|
+
}
|
|
475
|
+
static info(message) {
|
|
476
|
+
this.processMessage(message, 2);
|
|
477
|
+
}
|
|
478
|
+
static http(message) {
|
|
479
|
+
this.processMessage(message, 3);
|
|
480
|
+
}
|
|
481
|
+
static verbose(message) {
|
|
482
|
+
this.processMessage(message, 4);
|
|
483
|
+
}
|
|
484
|
+
static debug(message) {
|
|
485
|
+
this.processMessage(message, 5);
|
|
486
|
+
}
|
|
487
|
+
static silly(message) {
|
|
488
|
+
this.processMessage(message, 6);
|
|
489
|
+
}
|
|
490
|
+
static putNDJson(message, logLevel) {
|
|
491
|
+
let separator = this.NDJsonData.length !== 0 ? "\n" : "";
|
|
492
|
+
this.NDJsonData += separator + JSON.stringify({ time: new Date().toISOString(), level: logLevel, msg: message });
|
|
493
|
+
}
|
|
494
|
+
static getNDJson() {
|
|
495
|
+
return this.NDJsonData ?? "";
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
export {
|
|
499
|
+
Logger as default
|
|
500
|
+
};
|