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