@loglayer/transport-simple-pretty-terminal 2.2.7 → 2.2.9
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/dist/index.cjs +678 -633
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -118
- package/dist/index.d.ts +104 -118
- package/dist/index.js +642 -634
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,676 +1,721 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
4
22
|
|
|
5
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
let __loglayer_transport = require("@loglayer/transport");
|
|
25
|
+
__loglayer_transport = __toESM(__loglayer_transport);
|
|
26
|
+
let chalk = require("chalk");
|
|
27
|
+
chalk = __toESM(chalk);
|
|
28
|
+
let date_fns = require("date-fns");
|
|
29
|
+
date_fns = __toESM(date_fns);
|
|
6
30
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
//#region src/themes.ts
|
|
32
|
+
/**
|
|
33
|
+
* Moonlight - A dark theme with cool blue tones
|
|
34
|
+
* Inspired by moonlit nights and modern IDEs
|
|
35
|
+
*
|
|
36
|
+
* Color Palette:
|
|
37
|
+
* - Primary: Cool blues and soft greens
|
|
38
|
+
* - Accents: Warm yellows and soft reds
|
|
39
|
+
* - Background: Assumes dark terminal (black or very dark grey)
|
|
40
|
+
*
|
|
41
|
+
* Best used with:
|
|
42
|
+
* - Dark terminal themes
|
|
43
|
+
* - Night-time coding sessions
|
|
44
|
+
* - Environments where eye strain is a concern
|
|
45
|
+
*/
|
|
46
|
+
const moonlight = {
|
|
47
|
+
colors: {
|
|
48
|
+
trace: chalk.default.rgb(114, 135, 153),
|
|
49
|
+
debug: chalk.default.rgb(130, 170, 255),
|
|
50
|
+
info: chalk.default.rgb(195, 232, 141),
|
|
51
|
+
warn: chalk.default.rgb(255, 203, 107),
|
|
52
|
+
error: chalk.default.rgb(247, 118, 142),
|
|
53
|
+
fatal: chalk.default.bgRgb(247, 118, 142).white
|
|
54
|
+
},
|
|
55
|
+
logIdColor: chalk.default.rgb(84, 98, 117),
|
|
56
|
+
dataValueColor: chalk.default.rgb(209, 219, 231),
|
|
57
|
+
dataKeyColor: chalk.default.rgb(130, 170, 255)
|
|
28
58
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Sunlight - A light theme with warm tones
|
|
61
|
+
* Inspired by daylight reading and paper documentation
|
|
62
|
+
*
|
|
63
|
+
* Color Palette:
|
|
64
|
+
* - Primary: Deep, rich colors that contrast well with white
|
|
65
|
+
* - Accents: Earth tones and deep jewel tones
|
|
66
|
+
* - Background: Assumes light terminal (white or very light grey)
|
|
67
|
+
*
|
|
68
|
+
* Best used with:
|
|
69
|
+
* - Light terminal themes
|
|
70
|
+
* - Daytime coding sessions
|
|
71
|
+
* - High-glare environments
|
|
72
|
+
* - Printed documentation
|
|
73
|
+
*/
|
|
74
|
+
const sunlight = {
|
|
75
|
+
colors: {
|
|
76
|
+
trace: chalk.default.rgb(110, 110, 110),
|
|
77
|
+
debug: chalk.default.rgb(32, 96, 159),
|
|
78
|
+
info: chalk.default.rgb(35, 134, 54),
|
|
79
|
+
warn: chalk.default.rgb(176, 95, 0),
|
|
80
|
+
error: chalk.default.rgb(191, 0, 0),
|
|
81
|
+
fatal: chalk.default.bgRgb(191, 0, 0).white
|
|
82
|
+
},
|
|
83
|
+
logIdColor: chalk.default.rgb(110, 110, 110),
|
|
84
|
+
dataValueColor: chalk.default.rgb(0, 0, 0),
|
|
85
|
+
dataKeyColor: chalk.default.rgb(32, 96, 159)
|
|
47
86
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Neon - A dark theme with vibrant cyberpunk colors
|
|
89
|
+
* Inspired by neon-lit cityscapes and retro-futuristic aesthetics
|
|
90
|
+
*
|
|
91
|
+
* Color Palette:
|
|
92
|
+
* - Primary: Electric blues and hot pinks
|
|
93
|
+
* - Accents: Bright purples and cyber greens
|
|
94
|
+
* - Background: Assumes dark terminal (black or very dark grey)
|
|
95
|
+
*
|
|
96
|
+
* Best used with:
|
|
97
|
+
* - Dark terminal themes
|
|
98
|
+
* - High-contrast preferences
|
|
99
|
+
* - Modern, tech-focused applications
|
|
100
|
+
*/
|
|
101
|
+
const neon = {
|
|
102
|
+
colors: {
|
|
103
|
+
trace: chalk.default.rgb(108, 108, 255),
|
|
104
|
+
debug: chalk.default.rgb(255, 82, 246),
|
|
105
|
+
info: chalk.default.rgb(0, 255, 163),
|
|
106
|
+
warn: chalk.default.rgb(255, 231, 46),
|
|
107
|
+
error: chalk.default.rgb(255, 53, 91),
|
|
108
|
+
fatal: chalk.default.bgRgb(255, 53, 91).rgb(0, 255, 163)
|
|
109
|
+
},
|
|
110
|
+
logIdColor: chalk.default.rgb(187, 134, 252),
|
|
111
|
+
dataValueColor: chalk.default.rgb(255, 255, 255),
|
|
112
|
+
dataKeyColor: chalk.default.rgb(0, 255, 240)
|
|
69
113
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Nature - A light theme with organic, earthy colors
|
|
116
|
+
* Inspired by forest landscapes and natural elements
|
|
117
|
+
*
|
|
118
|
+
* Color Palette:
|
|
119
|
+
* - Primary: Deep forest greens and rich browns
|
|
120
|
+
* - Accents: Autumn reds and golden yellows
|
|
121
|
+
* - Background: Assumes light terminal (white or very light grey)
|
|
122
|
+
*
|
|
123
|
+
* Best used with:
|
|
124
|
+
* - Light terminal themes
|
|
125
|
+
* - Nature-inspired interfaces
|
|
126
|
+
* - Applications focusing on readability
|
|
127
|
+
*/
|
|
128
|
+
const nature = {
|
|
129
|
+
colors: {
|
|
130
|
+
trace: chalk.default.rgb(101, 115, 126),
|
|
131
|
+
debug: chalk.default.rgb(34, 139, 34),
|
|
132
|
+
info: chalk.default.rgb(46, 139, 87),
|
|
133
|
+
warn: chalk.default.rgb(218, 165, 32),
|
|
134
|
+
error: chalk.default.rgb(139, 69, 19),
|
|
135
|
+
fatal: chalk.default.bgRgb(139, 69, 19).white
|
|
136
|
+
},
|
|
137
|
+
logIdColor: chalk.default.rgb(101, 115, 126),
|
|
138
|
+
dataValueColor: chalk.default.rgb(0, 0, 0),
|
|
139
|
+
dataKeyColor: chalk.default.rgb(34, 139, 34)
|
|
88
140
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Pastel - A soft, calming theme with gentle colors
|
|
143
|
+
* Inspired by watercolor paintings and soft aesthetics
|
|
144
|
+
*
|
|
145
|
+
* Color Palette:
|
|
146
|
+
* - Primary: Soft pastels and muted tones
|
|
147
|
+
* - Accents: Gentle pinks and light blues
|
|
148
|
+
* - Background: Assumes light terminal (white or very light grey)
|
|
149
|
+
*
|
|
150
|
+
* Best used with:
|
|
151
|
+
* - Light terminal themes
|
|
152
|
+
* - Long coding sessions
|
|
153
|
+
* - Reduced visual stress
|
|
154
|
+
*/
|
|
155
|
+
const pastel = {
|
|
156
|
+
colors: {
|
|
157
|
+
trace: chalk.default.rgb(200, 200, 200),
|
|
158
|
+
debug: chalk.default.rgb(173, 216, 230),
|
|
159
|
+
info: chalk.default.rgb(144, 238, 144),
|
|
160
|
+
warn: chalk.default.rgb(255, 218, 185),
|
|
161
|
+
error: chalk.default.rgb(255, 182, 193),
|
|
162
|
+
fatal: chalk.default.bgRgb(255, 182, 193).rgb(105, 105, 105)
|
|
163
|
+
},
|
|
164
|
+
logIdColor: chalk.default.rgb(200, 200, 200),
|
|
165
|
+
dataValueColor: chalk.default.rgb(105, 105, 105),
|
|
166
|
+
dataKeyColor: chalk.default.rgb(173, 216, 230)
|
|
107
167
|
};
|
|
108
168
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/vendor/utils.js
|
|
171
|
+
/**
|
|
172
|
+
* Creates a string with the same length as `numSpaces` parameter
|
|
173
|
+
**/
|
|
113
174
|
function indent(numSpaces) {
|
|
114
|
-
|
|
175
|
+
return new Array(numSpaces + 1).join(" ");
|
|
115
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Gets the string length of the longer index in a hash
|
|
179
|
+
**/
|
|
116
180
|
function getMaxIndexLength(input) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
return maxWidth;
|
|
181
|
+
var maxWidth = 0;
|
|
182
|
+
Object.getOwnPropertyNames(input).forEach((key) => {
|
|
183
|
+
if (input[key] === void 0) return;
|
|
184
|
+
maxWidth = Math.max(maxWidth, key.length);
|
|
185
|
+
});
|
|
186
|
+
return maxWidth;
|
|
125
187
|
}
|
|
126
188
|
function isIsoStringDate(isoString) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
const testDate = new Date(isoString);
|
|
134
|
-
return !Number.isNaN(testDate.getTime());
|
|
189
|
+
if (typeof isoString !== "string") return false;
|
|
190
|
+
if (!/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?$/.test(isoString)) return false;
|
|
191
|
+
const testDate = new Date(isoString);
|
|
192
|
+
return !Number.isNaN(testDate.getTime());
|
|
135
193
|
}
|
|
136
194
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (Array.isArray(input) && isSerializable(input[0], true, options)) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/vendor/prettyjson.js
|
|
197
|
+
const conflictChars = /[^\w\s\n\r\v\t.,]/i;
|
|
198
|
+
const isPrintable = (input, options) => input !== void 0 || options.renderUndefined;
|
|
199
|
+
const isSerializable = (input, onlyPrimitives, options) => {
|
|
200
|
+
if (typeof input === "boolean" || typeof input === "number" || typeof input === "function" || input === null || input === void 0 || input instanceof Date) return true;
|
|
201
|
+
if (typeof input === "string" && input.indexOf("\n") === -1) return true;
|
|
202
|
+
if (options.inlineArrays && !onlyPrimitives) {
|
|
203
|
+
if (Array.isArray(input) && isSerializable(input[0], true, options)) return true;
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
153
206
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
207
|
+
/**
|
|
208
|
+
* @param {Function} colorFn
|
|
209
|
+
* @param {PrettyJSONOptions} options
|
|
210
|
+
*/
|
|
211
|
+
const getColorRenderer = (colorFn, options) => {
|
|
212
|
+
if (options.noColor) return (text) => text;
|
|
213
|
+
if (typeof colorFn !== "function") return (text) => text;
|
|
214
|
+
return colorFn;
|
|
162
215
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (input === null || input === void 0) {
|
|
181
|
-
return getColorRenderer(options.nullUndefinedColor, options)(sInput);
|
|
182
|
-
}
|
|
183
|
-
if (typeof input === "number") {
|
|
184
|
-
if (input >= 0) {
|
|
185
|
-
return getColorRenderer(options.positiveNumberColor, options)(sInput);
|
|
186
|
-
}
|
|
187
|
-
return getColorRenderer(options.negativeNumberColor, options)(sInput);
|
|
188
|
-
}
|
|
189
|
-
if (typeof input === "function") {
|
|
190
|
-
return "function() {}";
|
|
191
|
-
}
|
|
192
|
-
if (Array.isArray(input)) {
|
|
193
|
-
return input.join(", ");
|
|
194
|
-
}
|
|
195
|
-
return sInput;
|
|
216
|
+
const addColorToData = (input, options) => {
|
|
217
|
+
if (options.noColor) return input;
|
|
218
|
+
if (input instanceof Date) return getColorRenderer(options.dateColor, options)(input.toISOString());
|
|
219
|
+
if (typeof input === "string") {
|
|
220
|
+
if (isIsoStringDate(input)) return getColorRenderer(options.dateColor, options)(input);
|
|
221
|
+
return getColorRenderer(options.stringColor, options)(input);
|
|
222
|
+
}
|
|
223
|
+
const sInput = `${input}`;
|
|
224
|
+
if (typeof input === "boolean") return getColorRenderer(options.booleanColor, options)(sInput);
|
|
225
|
+
if (input === null || input === void 0) return getColorRenderer(options.nullUndefinedColor, options)(sInput);
|
|
226
|
+
if (typeof input === "number") {
|
|
227
|
+
if (input >= 0) return getColorRenderer(options.positiveNumberColor, options)(sInput);
|
|
228
|
+
return getColorRenderer(options.negativeNumberColor, options)(sInput);
|
|
229
|
+
}
|
|
230
|
+
if (typeof input === "function") return "function() {}";
|
|
231
|
+
if (Array.isArray(input)) return input.join(", ");
|
|
232
|
+
return sInput;
|
|
196
233
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
234
|
+
const colorMultilineString = (options, line) => getColorRenderer(options.multilineStringColor, options)(line);
|
|
235
|
+
const indentLines = (string, spaces, options) => {
|
|
236
|
+
let lines = string.split("\n");
|
|
237
|
+
lines = lines.map((line) => indent(spaces) + colorMultilineString(options, line));
|
|
238
|
+
return lines.join("\n");
|
|
202
239
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
const maxIndexLength = options.noAlign ? 0 : getMaxIndexLength(data);
|
|
256
|
-
let key;
|
|
257
|
-
const output = [];
|
|
258
|
-
Object.getOwnPropertyNames(data).forEach((i) => {
|
|
259
|
-
if (!isPrintable(data[i], options)) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
key = `${i}: `;
|
|
263
|
-
key = getColorRenderer(options.keysColor, options)(key);
|
|
264
|
-
key = indent(indentation) + key;
|
|
265
|
-
if (isSerializable(data[i], false, options)) {
|
|
266
|
-
const nextIndentation = options.noAlign ? 0 : maxIndexLength - i.length;
|
|
267
|
-
key += renderToArray(data[i], options, nextIndentation)[0];
|
|
268
|
-
output.push(key);
|
|
269
|
-
} else {
|
|
270
|
-
output.push(key);
|
|
271
|
-
output.push.apply(output, renderToArray(data[i], options, indentation + options.defaultIndentation));
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
return output;
|
|
240
|
+
const renderToArray = (data, options, indentation) => {
|
|
241
|
+
if (typeof data === "string" && data.match(conflictChars) && options.escape) data = JSON.stringify(data);
|
|
242
|
+
if (!isPrintable(data, options)) return [];
|
|
243
|
+
if (isSerializable(data, false, options)) return [indent(indentation) + addColorToData(data, options)];
|
|
244
|
+
if (typeof data === "string") return [
|
|
245
|
+
indent(indentation) + colorMultilineString(options, "\"\"\""),
|
|
246
|
+
indentLines(data, indentation + options.defaultIndentation, options),
|
|
247
|
+
indent(indentation) + colorMultilineString(options, "\"\"\"")
|
|
248
|
+
];
|
|
249
|
+
if (Array.isArray(data)) {
|
|
250
|
+
if (data.length === 0) return [indent(indentation) + options.emptyArrayMsg];
|
|
251
|
+
if (options.collapseArrays && data.length > 0) return [`${indent(indentation)}[... ${data.length} items]`];
|
|
252
|
+
const outputArray = [];
|
|
253
|
+
data.forEach((element) => {
|
|
254
|
+
if (!isPrintable(element, options)) return;
|
|
255
|
+
let line = "- ";
|
|
256
|
+
line = getColorRenderer(options.dashColor, options)(line);
|
|
257
|
+
line = indent(indentation) + line;
|
|
258
|
+
if (isSerializable(element, false, options)) {
|
|
259
|
+
line += renderToArray(element, options, 0)[0];
|
|
260
|
+
outputArray.push(line);
|
|
261
|
+
} else {
|
|
262
|
+
outputArray.push(line);
|
|
263
|
+
outputArray.push.apply(outputArray, renderToArray(element, options, indentation + options.defaultIndentation));
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
return outputArray;
|
|
267
|
+
}
|
|
268
|
+
if (data instanceof Error) return renderToArray({
|
|
269
|
+
message: data.message,
|
|
270
|
+
stack: data.stack.split("\n")
|
|
271
|
+
}, options, indentation);
|
|
272
|
+
const maxIndexLength = options.noAlign ? 0 : getMaxIndexLength(data);
|
|
273
|
+
let key;
|
|
274
|
+
const output = [];
|
|
275
|
+
Object.getOwnPropertyNames(data).forEach((i) => {
|
|
276
|
+
if (!isPrintable(data[i], options)) return;
|
|
277
|
+
key = `${i}: `;
|
|
278
|
+
key = getColorRenderer(options.keysColor, options)(key);
|
|
279
|
+
key = indent(indentation) + key;
|
|
280
|
+
if (isSerializable(data[i], false, options)) {
|
|
281
|
+
const nextIndentation = options.noAlign ? 0 : maxIndexLength - i.length;
|
|
282
|
+
key += renderToArray(data[i], options, nextIndentation)[0];
|
|
283
|
+
output.push(key);
|
|
284
|
+
} else {
|
|
285
|
+
output.push(key);
|
|
286
|
+
output.push.apply(output, renderToArray(data[i], options, indentation + options.defaultIndentation));
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
return output;
|
|
275
290
|
};
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
291
|
+
/**
|
|
292
|
+
* @typedef {Object} PrettyJSONOptions
|
|
293
|
+
* @property {Function} [stringColor=null] Chalk color function for strings
|
|
294
|
+
* @property {Function} [multilineStringColor=null] Chalk color function for multiline strings
|
|
295
|
+
* @property {Function} [keysColor=chalk.green] Chalk color function for keys in hashes
|
|
296
|
+
* @property {Function} [dashColor=chalk.green] Chalk color function for dashes in arrays
|
|
297
|
+
* @property {Function} [numberColor=chalk.blue] Default Chalk color function for numbers
|
|
298
|
+
* @property {Function} [positiveNumberColor=numberColor] Chalk color function for positive numbers
|
|
299
|
+
* @property {Function} [negativeNumberColor=numberColor] Chalk color function for negative numbers
|
|
300
|
+
* @property {Function} [booleanColor=chalk.cyan] Chalk color function for boolean values
|
|
301
|
+
* @property {Function} [nullUndefinedColor=chalk.grey] Chalk color function for null || undefined
|
|
302
|
+
* @property {Function} [dateColor=chalk.magenta] Chalk color function for Date objects
|
|
303
|
+
* @property {number} [defaultIndentation=2] Indentation spaces per object level
|
|
304
|
+
* @property {string} [emptyArrayMsg="(empty array)"] Replace empty strings with
|
|
305
|
+
* @property {boolean} [noColor] Flag to disable colors
|
|
306
|
+
* @property {boolean} [noAlign] Flag to disable alignment
|
|
307
|
+
* @property {boolean} [escape] Flag to escape printed content
|
|
308
|
+
* @property {boolean} [collapseArrays] Flag to collapse arrays
|
|
309
|
+
*/
|
|
310
|
+
/**
|
|
311
|
+
* Mutating function that ensures we have a valid options object
|
|
312
|
+
* @param {PrettyJSONOptions} options
|
|
313
|
+
* @returns PrettyJSONOptions
|
|
314
|
+
*/
|
|
315
|
+
const validateOptionsAndSetDefaults = (options) => {
|
|
316
|
+
options = options || {};
|
|
317
|
+
options.emptyArrayMsg = options.emptyArrayMsg || "(empty array)";
|
|
318
|
+
options.keysColor = options.keysColor || chalk.default.green;
|
|
319
|
+
options.dashColor = options.dashColor || chalk.default.green;
|
|
320
|
+
options.booleanColor = options.booleanColor || chalk.default.cyan;
|
|
321
|
+
options.nullUndefinedColor = options.nullUndefinedColor || chalk.default.grey;
|
|
322
|
+
options.numberColor = options.numberColor || chalk.default.blue;
|
|
323
|
+
options.positiveNumberColor = options.positiveNumberColor || options.numberColor;
|
|
324
|
+
options.negativeNumberColor = options.negativeNumberColor || options.numberColor;
|
|
325
|
+
options.dateColor = options.dateColor || chalk.default.magenta;
|
|
326
|
+
options.defaultIndentation = options.defaultIndentation || 2;
|
|
327
|
+
options.noColor = !!options.noColor;
|
|
328
|
+
options.noAlign = !!options.noAlign;
|
|
329
|
+
options.escape = !!options.escape;
|
|
330
|
+
options.renderUndefined = !!options.renderUndefined;
|
|
331
|
+
options.collapseArrays = !!options.collapseArrays;
|
|
332
|
+
options.stringColor = options.stringColor || null;
|
|
333
|
+
options.multilineStringColor = options.multilineStringColor || options.stringColor || null;
|
|
334
|
+
return options;
|
|
296
335
|
};
|
|
336
|
+
/**
|
|
337
|
+
* ### Render function
|
|
338
|
+
* *Parameters:*
|
|
339
|
+
*
|
|
340
|
+
* @param {*} data: Data to render
|
|
341
|
+
* @param {PrettyJSONOptions} options: Hash of different options
|
|
342
|
+
* @param {*} indentation **`indentation`**: Base indentation of the output
|
|
343
|
+
*
|
|
344
|
+
* *Example of options hash:*
|
|
345
|
+
*
|
|
346
|
+
* {
|
|
347
|
+
* emptyArrayMsg: '(empty)', // Rendered message on empty strings
|
|
348
|
+
* keysColor: 'blue', // Color for keys in hashes
|
|
349
|
+
* dashColor: 'red', // Color for the dashes in arrays
|
|
350
|
+
* stringColor: 'grey', // Color for strings
|
|
351
|
+
* multilineStringColor: 'cyan' // Color for multiline strings
|
|
352
|
+
* defaultIndentation: 2 // Indentation on nested objects
|
|
353
|
+
* }
|
|
354
|
+
* @returns string with the rendered data
|
|
355
|
+
*/
|
|
297
356
|
function render(data, options, indentation) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
357
|
+
indentation = indentation || 0;
|
|
358
|
+
options = validateOptionsAndSetDefaults(options);
|
|
359
|
+
return renderToArray(data, options, indentation).join("\n");
|
|
301
360
|
}
|
|
302
361
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/views/utils.ts
|
|
364
|
+
/**
|
|
365
|
+
* Formats a timestamp into a readable string.
|
|
366
|
+
*
|
|
367
|
+
* @param timestamp - Unix timestamp in milliseconds
|
|
368
|
+
* @param colorFn - Chalk function to color the timestamp
|
|
369
|
+
* @param timestampFormat - Custom format string (date-fns) or function. Defaults to "HH:mm:ss.SSS"
|
|
370
|
+
* @returns Formatted timestamp string
|
|
371
|
+
*/
|
|
306
372
|
function formatTimestamp(timestamp, colorFn, timestampFormat = "HH:mm:ss.SSS") {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const date = new Date(timestamp);
|
|
312
|
-
formattedTime = _datefns.format.call(void 0, date, timestampFormat);
|
|
313
|
-
}
|
|
314
|
-
return colorFn(`[${formattedTime}]`);
|
|
373
|
+
let formattedTime;
|
|
374
|
+
if (typeof timestampFormat === "function") formattedTime = timestampFormat(timestamp);
|
|
375
|
+
else formattedTime = (0, date_fns.format)(new Date(timestamp), timestampFormat);
|
|
376
|
+
return colorFn(`[${formattedTime}]`);
|
|
315
377
|
}
|
|
378
|
+
/**
|
|
379
|
+
* Gets the appropriate color function for a log level.
|
|
380
|
+
*
|
|
381
|
+
* @param level - Log level string
|
|
382
|
+
* @param colors - Color configuration object
|
|
383
|
+
* @returns Chalk function for the log level
|
|
384
|
+
*/
|
|
316
385
|
function getLevelColor(level, colors) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return colors.warn || _chalk2.default.white;
|
|
327
|
-
case "error":
|
|
328
|
-
return colors.error || _chalk2.default.white;
|
|
329
|
-
case "fatal":
|
|
330
|
-
return colors.fatal || _chalk2.default.white;
|
|
331
|
-
default:
|
|
332
|
-
return colors.info || _chalk2.default.white;
|
|
333
|
-
}
|
|
386
|
+
switch (level.toLowerCase()) {
|
|
387
|
+
case "trace": return colors.trace || chalk.default.white;
|
|
388
|
+
case "debug": return colors.debug || chalk.default.white;
|
|
389
|
+
case "info": return colors.info || chalk.default.white;
|
|
390
|
+
case "warn": return colors.warn || chalk.default.white;
|
|
391
|
+
case "error": return colors.error || chalk.default.white;
|
|
392
|
+
case "fatal": return colors.fatal || chalk.default.white;
|
|
393
|
+
default: return colors.info || chalk.default.white;
|
|
394
|
+
}
|
|
334
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* Formats a value for display.
|
|
398
|
+
*/
|
|
335
399
|
function formatValue(value, expanded = false, collapseArrays = true) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
400
|
+
if (typeof value === "string") return value;
|
|
401
|
+
if (typeof value === "number" || typeof value === "boolean") return value.toString();
|
|
402
|
+
if (value === null) return "null";
|
|
403
|
+
if (value === void 0) return "undefined";
|
|
404
|
+
if (Array.isArray(value)) return expanded ? JSON.stringify(value) : collapseArrays ? "[...]" : value.toString();
|
|
405
|
+
if (typeof value === "object") return expanded ? JSON.stringify(value) : "{...}";
|
|
406
|
+
return value.toString();
|
|
343
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* Formats structured data for inline display with depth limiting.
|
|
410
|
+
*
|
|
411
|
+
* @param data - The data to format
|
|
412
|
+
* @param config - View configuration for colors
|
|
413
|
+
* @param maxDepth - Maximum depth for nested objects
|
|
414
|
+
* @param expanded - Whether to show full depth (for inline view mode)
|
|
415
|
+
* @param collapseArrays - Whether to collapse arrays to summary format
|
|
416
|
+
* @returns Formatted data string
|
|
417
|
+
*/
|
|
344
418
|
function formatInlineData(data, config, maxDepth, expanded = false, collapseArrays = true) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
pairs.push(
|
|
359
|
-
`${config.dataKeyColor(fullKey)}=${config.dataValueColor(formatValue(value, expanded, collapseArrays))}`
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
traverse(data);
|
|
365
|
-
const result = pairs.join(" ");
|
|
366
|
-
return result;
|
|
419
|
+
if (!data) return "";
|
|
420
|
+
const pairs = [];
|
|
421
|
+
const traverse = (obj, prefix = "", depth = 0) => {
|
|
422
|
+
if (!expanded && depth >= maxDepth) return;
|
|
423
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
424
|
+
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
425
|
+
if (value && typeof value === "object" && !Array.isArray(value)) if (expanded) pairs.push(`${config.dataKeyColor(fullKey)}=${config.dataValueColor(JSON.stringify(value))}`);
|
|
426
|
+
else traverse(value, fullKey, depth + 1);
|
|
427
|
+
else pairs.push(`${config.dataKeyColor(fullKey)}=${config.dataValueColor(formatValue(value, expanded, collapseArrays))}`);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
traverse(data);
|
|
431
|
+
return pairs.join(" ");
|
|
367
432
|
}
|
|
368
433
|
|
|
369
|
-
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/views/SimpleView.ts
|
|
436
|
+
/**
|
|
437
|
+
* Handles rendering of the simple view mode.
|
|
438
|
+
* Supports three display modes:
|
|
439
|
+
* - Message-only: Shows timestamp, level and message
|
|
440
|
+
* - Inline: Shows all details with complete data inline
|
|
441
|
+
* - Expanded: Shows timestamp, level, and message on first line, with data on indented separate lines
|
|
442
|
+
*/
|
|
370
443
|
var SimpleView = class {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
const jsonLines = render(JSON.parse(entry.data), {
|
|
487
|
-
defaultIndentation: 2,
|
|
488
|
-
keysColor: this.config.config.dataKeyColor,
|
|
489
|
-
dashColor: this.config.config.dataKeyColor,
|
|
490
|
-
numberColor: this.config.config.dataValueColor,
|
|
491
|
-
stringColor: this.config.config.dataValueColor,
|
|
492
|
-
multilineStringColor: this.config.config.dataValueColor,
|
|
493
|
-
positiveNumberColor: this.config.config.dataValueColor,
|
|
494
|
-
negativeNumberColor: this.config.config.dataValueColor,
|
|
495
|
-
booleanColor: this.config.config.dataValueColor,
|
|
496
|
-
nullUndefinedColor: this.config.config.dataValueColor,
|
|
497
|
-
dateColor: this.config.config.dataValueColor,
|
|
498
|
-
collapseArrays: this.collapseArrays
|
|
499
|
-
}).split("\n");
|
|
500
|
-
for (const line of jsonLines) {
|
|
501
|
-
if (line.trim() !== "") {
|
|
502
|
-
this.writeMessage(` ${line}`, entry.level);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
break;
|
|
507
|
-
}
|
|
508
|
-
default: {
|
|
509
|
-
const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
|
|
510
|
-
const fullData = entry.data ? formatInlineData(JSON.parse(entry.data), this.config.config, this.maxInlineDepth, true, this.collapseArrays) : "";
|
|
511
|
-
const expandedLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}${fullData ? ` ${fullData}` : ""}`;
|
|
512
|
-
this.writeMessage(expandedLine, entry.level, parsedData);
|
|
513
|
-
break;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
444
|
+
config;
|
|
445
|
+
viewMode;
|
|
446
|
+
maxInlineDepth;
|
|
447
|
+
showLogId;
|
|
448
|
+
timestampFormat;
|
|
449
|
+
collapseArrays;
|
|
450
|
+
flattenNestedObjects;
|
|
451
|
+
runtime;
|
|
452
|
+
includeDataInBrowserConsole;
|
|
453
|
+
constructor(config) {
|
|
454
|
+
this.config = config;
|
|
455
|
+
this.viewMode = config.viewMode;
|
|
456
|
+
this.maxInlineDepth = config.maxInlineDepth;
|
|
457
|
+
this.showLogId = config.showLogId;
|
|
458
|
+
this.timestampFormat = config.timestampFormat;
|
|
459
|
+
this.collapseArrays = config.collapseArrays !== false;
|
|
460
|
+
this.flattenNestedObjects = config.flattenNestedObjects !== false;
|
|
461
|
+
this.runtime = config.runtime;
|
|
462
|
+
this.includeDataInBrowserConsole = config.includeDataInBrowserConsole || false;
|
|
463
|
+
}
|
|
464
|
+
getConfig() {
|
|
465
|
+
return this.config;
|
|
466
|
+
}
|
|
467
|
+
getViewMode() {
|
|
468
|
+
return this.viewMode;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Writes a message to the appropriate output based on runtime
|
|
472
|
+
*/
|
|
473
|
+
writeMessage(message, level, data) {
|
|
474
|
+
if (this.runtime === "node") process?.stdout?.write?.(`${message}\n`);
|
|
475
|
+
else {
|
|
476
|
+
const shouldIncludeData = this.includeDataInBrowserConsole && data !== void 0;
|
|
477
|
+
switch (level) {
|
|
478
|
+
case "trace":
|
|
479
|
+
if (shouldIncludeData) console.debug(message, data);
|
|
480
|
+
else console.debug(message);
|
|
481
|
+
break;
|
|
482
|
+
case "debug":
|
|
483
|
+
if (shouldIncludeData) console.debug(message, data);
|
|
484
|
+
else console.debug(message);
|
|
485
|
+
break;
|
|
486
|
+
case "info":
|
|
487
|
+
if (shouldIncludeData) console.info(message, data);
|
|
488
|
+
else console.info(message);
|
|
489
|
+
break;
|
|
490
|
+
case "warn":
|
|
491
|
+
if (shouldIncludeData) console.warn(message, data);
|
|
492
|
+
else console.warn(message);
|
|
493
|
+
break;
|
|
494
|
+
case "error":
|
|
495
|
+
case "fatal":
|
|
496
|
+
if (shouldIncludeData) console.error(message, data);
|
|
497
|
+
else console.error(message);
|
|
498
|
+
break;
|
|
499
|
+
default:
|
|
500
|
+
if (shouldIncludeData) console.log(message, data);
|
|
501
|
+
else console.log(message);
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Renders a single log entry based on the current view mode
|
|
508
|
+
*/
|
|
509
|
+
renderLogLine(entry) {
|
|
510
|
+
const chevron = getLevelColor(entry.level, this.config.config.colors)(`▶ ${entry.level.toUpperCase()} `);
|
|
511
|
+
const message = entry.message || "(no message)";
|
|
512
|
+
const timestamp = formatTimestamp(entry.timestamp, this.config.config.logIdColor, this.timestampFormat);
|
|
513
|
+
const parsedData = entry.data ? JSON.parse(entry.data) : void 0;
|
|
514
|
+
switch (this.viewMode) {
|
|
515
|
+
case "message-only": {
|
|
516
|
+
const condensedLine = `${timestamp} ${chevron}${message}`;
|
|
517
|
+
this.writeMessage(condensedLine, entry.level, parsedData);
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
case "inline": {
|
|
521
|
+
const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
|
|
522
|
+
const fullData = entry.data ? formatInlineData(JSON.parse(entry.data), this.config.config, this.maxInlineDepth, !this.flattenNestedObjects, this.collapseArrays) : "";
|
|
523
|
+
const expandedLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}${fullData ? ` ${fullData}` : ""}`;
|
|
524
|
+
this.writeMessage(expandedLine, entry.level, parsedData);
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
case "expanded": {
|
|
528
|
+
const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
|
|
529
|
+
const firstLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}`;
|
|
530
|
+
this.writeMessage(firstLine, entry.level, parsedData);
|
|
531
|
+
if (entry.data) {
|
|
532
|
+
const jsonLines = render(JSON.parse(entry.data), {
|
|
533
|
+
defaultIndentation: 2,
|
|
534
|
+
keysColor: this.config.config.dataKeyColor,
|
|
535
|
+
dashColor: this.config.config.dataKeyColor,
|
|
536
|
+
numberColor: this.config.config.dataValueColor,
|
|
537
|
+
stringColor: this.config.config.dataValueColor,
|
|
538
|
+
multilineStringColor: this.config.config.dataValueColor,
|
|
539
|
+
positiveNumberColor: this.config.config.dataValueColor,
|
|
540
|
+
negativeNumberColor: this.config.config.dataValueColor,
|
|
541
|
+
booleanColor: this.config.config.dataValueColor,
|
|
542
|
+
nullUndefinedColor: this.config.config.dataValueColor,
|
|
543
|
+
dateColor: this.config.config.dataValueColor,
|
|
544
|
+
collapseArrays: this.collapseArrays
|
|
545
|
+
}).split("\n");
|
|
546
|
+
for (const line of jsonLines) if (line.trim() !== "") this.writeMessage(` ${line}`, entry.level);
|
|
547
|
+
}
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
default: {
|
|
551
|
+
const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
|
|
552
|
+
const fullData = entry.data ? formatInlineData(JSON.parse(entry.data), this.config.config, this.maxInlineDepth, true, this.collapseArrays) : "";
|
|
553
|
+
const expandedLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}${fullData ? ` ${fullData}` : ""}`;
|
|
554
|
+
this.writeMessage(expandedLine, entry.level, parsedData);
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
517
559
|
};
|
|
518
560
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
*/
|
|
657
|
-
getViewMode() {
|
|
658
|
-
return this.renderer.getViewMode();
|
|
659
|
-
}
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/SimplePrettyTerminalTransport.ts
|
|
563
|
+
/**
|
|
564
|
+
* Main transport class that handles simple pretty terminal output.
|
|
565
|
+
* This class provides the display functionality of PrettyTerminal without interactive features.
|
|
566
|
+
*
|
|
567
|
+
* The transport supports three view modes:
|
|
568
|
+
* 1. Inline: Shows all information with complete data structures inline (no truncation)
|
|
569
|
+
* 2. Message-only: Shows only the timestamp, log level and message for a cleaner output (no data shown)
|
|
570
|
+
* 3. Expanded: Shows timestamp, level, and message on first line, with data on indented separate lines
|
|
571
|
+
*/
|
|
572
|
+
var SimplePrettyTerminalTransport = class extends __loglayer_transport.LoggerlessTransport {
|
|
573
|
+
/** Handles rendering and formatting of logs */
|
|
574
|
+
renderer;
|
|
575
|
+
/** Configuration options */
|
|
576
|
+
config;
|
|
577
|
+
/**
|
|
578
|
+
* Creates a new SimplePrettyTerminalTransport instance.
|
|
579
|
+
*
|
|
580
|
+
* @param config - Configuration options for the transport
|
|
581
|
+
*/
|
|
582
|
+
constructor(config) {
|
|
583
|
+
super(config);
|
|
584
|
+
this.config = config;
|
|
585
|
+
if (config.enabled === false) return;
|
|
586
|
+
const maxInlineDepth = config.maxInlineDepth || 4;
|
|
587
|
+
const theme = config.theme || moonlight;
|
|
588
|
+
const viewMode = config.viewMode || "inline";
|
|
589
|
+
const showLogId = config.showLogId || false;
|
|
590
|
+
const timestampFormat = config.timestampFormat || "HH:mm:ss.SSS";
|
|
591
|
+
const collapseArrays = config.collapseArrays !== false;
|
|
592
|
+
const flattenNestedObjects = config.flattenNestedObjects !== false;
|
|
593
|
+
const runtime = config.runtime;
|
|
594
|
+
this.renderer = new SimpleView({
|
|
595
|
+
viewMode,
|
|
596
|
+
maxInlineDepth,
|
|
597
|
+
showLogId,
|
|
598
|
+
timestampFormat,
|
|
599
|
+
collapseArrays,
|
|
600
|
+
flattenNestedObjects,
|
|
601
|
+
runtime,
|
|
602
|
+
includeDataInBrowserConsole: config.includeDataInBrowserConsole || false,
|
|
603
|
+
config: {
|
|
604
|
+
colors: {
|
|
605
|
+
trace: chalk.default.gray,
|
|
606
|
+
debug: chalk.default.blue,
|
|
607
|
+
info: chalk.default.green,
|
|
608
|
+
warn: chalk.default.yellow,
|
|
609
|
+
error: chalk.default.red,
|
|
610
|
+
fatal: chalk.default.bgRed.white,
|
|
611
|
+
...theme.colors
|
|
612
|
+
},
|
|
613
|
+
logIdColor: theme.logIdColor || chalk.default.dim,
|
|
614
|
+
dataValueColor: theme.dataValueColor || chalk.default.white,
|
|
615
|
+
dataKeyColor: theme.dataKeyColor || chalk.default.dim
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Generates a random ID for each log entry.
|
|
621
|
+
* Uses base36 encoding for compact, readable IDs.
|
|
622
|
+
*
|
|
623
|
+
* @returns A 6-character string ID
|
|
624
|
+
* @example
|
|
625
|
+
* "a1b2c3" // Example generated ID
|
|
626
|
+
*/
|
|
627
|
+
generateId() {
|
|
628
|
+
return Math.random().toString(36).substring(2, 8);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Main transport method that receives logs from LogLayer.
|
|
632
|
+
* This method is called for each log event and handles:
|
|
633
|
+
* - Generating a unique ID for the log
|
|
634
|
+
* - Converting the log data to a storable format
|
|
635
|
+
* - Rendering the log using the SimpleView renderer
|
|
636
|
+
*
|
|
637
|
+
* @param logLevel - The severity level of the log
|
|
638
|
+
* @param messages - Array of message strings to be joined
|
|
639
|
+
* @param data - Additional structured data to be logged
|
|
640
|
+
* @param hasData - Whether the log includes additional data
|
|
641
|
+
* @returns The original messages array
|
|
642
|
+
*/
|
|
643
|
+
shipToLogger({ logLevel, messages, data, hasData }) {
|
|
644
|
+
if (this.config.enabled === false) return messages;
|
|
645
|
+
const entry = {
|
|
646
|
+
id: this.generateId(),
|
|
647
|
+
timestamp: Date.now(),
|
|
648
|
+
level: logLevel,
|
|
649
|
+
message: messages.join(" "),
|
|
650
|
+
data: hasData ? JSON.stringify(data) : null
|
|
651
|
+
};
|
|
652
|
+
this.renderer.renderLogLine(entry);
|
|
653
|
+
return messages;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Changes the view mode for log display.
|
|
657
|
+
*
|
|
658
|
+
* @param viewMode - The new view mode to use
|
|
659
|
+
*/
|
|
660
|
+
setViewMode(viewMode) {
|
|
661
|
+
if (this.config.enabled === false) return;
|
|
662
|
+
const theme = this.config.theme || moonlight;
|
|
663
|
+
const runtime = this.config.runtime;
|
|
664
|
+
const viewConfig = {
|
|
665
|
+
colors: {
|
|
666
|
+
trace: chalk.default.gray,
|
|
667
|
+
debug: chalk.default.blue,
|
|
668
|
+
info: chalk.default.green,
|
|
669
|
+
warn: chalk.default.yellow,
|
|
670
|
+
error: chalk.default.red,
|
|
671
|
+
fatal: chalk.default.bgRed.white,
|
|
672
|
+
...theme.colors
|
|
673
|
+
},
|
|
674
|
+
logIdColor: theme.logIdColor || chalk.default.dim,
|
|
675
|
+
dataValueColor: theme.dataValueColor || chalk.default.white,
|
|
676
|
+
dataKeyColor: theme.dataKeyColor || chalk.default.dim
|
|
677
|
+
};
|
|
678
|
+
this.renderer = new SimpleView({
|
|
679
|
+
viewMode,
|
|
680
|
+
maxInlineDepth: this.config.maxInlineDepth || 4,
|
|
681
|
+
showLogId: this.config.showLogId || false,
|
|
682
|
+
timestampFormat: this.config.timestampFormat || "HH:mm:ss.SSS",
|
|
683
|
+
collapseArrays: this.config.collapseArrays !== false,
|
|
684
|
+
flattenNestedObjects: this.config.flattenNestedObjects !== false,
|
|
685
|
+
runtime,
|
|
686
|
+
includeDataInBrowserConsole: this.config.includeDataInBrowserConsole || false,
|
|
687
|
+
config: viewConfig
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Gets the current view mode.
|
|
692
|
+
*
|
|
693
|
+
* @returns The current view mode
|
|
694
|
+
*/
|
|
695
|
+
getViewMode() {
|
|
696
|
+
return this.renderer.getViewMode();
|
|
697
|
+
}
|
|
660
698
|
};
|
|
661
699
|
|
|
662
|
-
|
|
663
|
-
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/index.ts
|
|
664
702
|
function getSimplePrettyTerminal(config) {
|
|
665
|
-
|
|
703
|
+
return new SimplePrettyTerminalTransport(config);
|
|
666
704
|
}
|
|
667
705
|
|
|
706
|
+
//#endregion
|
|
707
|
+
exports.SimplePrettyTerminalTransport = SimplePrettyTerminalTransport;
|
|
708
|
+
exports.getSimplePrettyTerminal = getSimplePrettyTerminal;
|
|
709
|
+
exports.moonlight = moonlight;
|
|
710
|
+
exports.nature = nature;
|
|
711
|
+
exports.neon = neon;
|
|
712
|
+
exports.pastel = pastel;
|
|
713
|
+
exports.sunlight = sunlight;
|
|
714
|
+
Object.keys(chalk).forEach(function (k) {
|
|
715
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
716
|
+
enumerable: true,
|
|
717
|
+
get: function () { return chalk[k]; }
|
|
718
|
+
});
|
|
719
|
+
});
|
|
668
720
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
exports.SimplePrettyTerminalTransport = SimplePrettyTerminalTransport; exports.getSimplePrettyTerminal = getSimplePrettyTerminal; exports.moonlight = moonlight; exports.nature = nature; exports.neon = neon; exports.pastel = pastel; exports.sunlight = sunlight;
|
|
676
721
|
//# sourceMappingURL=index.cjs.map
|