@loglayer/transport-simple-pretty-terminal 2.2.6 → 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.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
- var moonlight = {
8
- colors: {
9
- trace: chalk.rgb(114, 135, 153),
10
- // Muted blue-grey for less important info
11
- debug: chalk.rgb(130, 170, 255),
12
- // Soft blue that pops but doesn't strain
13
- info: chalk.rgb(195, 232, 141),
14
- // Sage green for good readability
15
- warn: chalk.rgb(255, 203, 107),
16
- // Warm yellow, less harsh than pure yellow
17
- error: chalk.rgb(247, 118, 142),
18
- // Soft red that stands out without being aggressive
19
- fatal: chalk.bgRgb(247, 118, 142).white
20
- // Inverted soft red for maximum visibility
21
- },
22
- logIdColor: chalk.rgb(84, 98, 117),
23
- // Darker blue-grey for secondary information
24
- dataValueColor: chalk.rgb(209, 219, 231),
25
- // Light grey-blue for primary content
26
- dataKeyColor: chalk.rgb(130, 170, 255)
27
- // Matching debug blue for consistency
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
- var sunlight = {
30
- colors: {
31
- trace: chalk.rgb(110, 110, 110),
32
- // Dark grey for subtle information
33
- debug: chalk.rgb(32, 96, 159),
34
- // Deep blue for strong contrast on white
35
- info: chalk.rgb(35, 134, 54),
36
- // Forest green, easier on the eyes than bright green
37
- warn: chalk.rgb(176, 95, 0),
38
- // Brown-orange for natural warning color
39
- error: chalk.rgb(191, 0, 0),
40
- // Deep red for clear visibility on light backgrounds
41
- fatal: chalk.bgRgb(191, 0, 0).white
42
- // White on deep red for critical issues
43
- },
44
- logIdColor: chalk.rgb(110, 110, 110),
45
- dataValueColor: chalk.rgb(0, 0, 0),
46
- dataKeyColor: chalk.rgb(32, 96, 159)
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
- var neon = {
49
- colors: {
50
- trace: chalk.rgb(108, 108, 255),
51
- // Electric blue
52
- debug: chalk.rgb(255, 82, 246),
53
- // Hot pink
54
- info: chalk.rgb(0, 255, 163),
55
- // Cyber green
56
- warn: chalk.rgb(255, 231, 46),
57
- // Electric yellow
58
- error: chalk.rgb(255, 53, 91),
59
- // Neon red
60
- fatal: chalk.bgRgb(255, 53, 91).rgb(0, 255, 163)
61
- // Neon red bg with cyber green text
62
- },
63
- logIdColor: chalk.rgb(187, 134, 252),
64
- // Bright purple
65
- dataValueColor: chalk.rgb(255, 255, 255),
66
- // Pure white
67
- dataKeyColor: chalk.rgb(0, 255, 240)
68
- // Cyan
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
- var nature = {
71
- colors: {
72
- trace: chalk.rgb(101, 115, 126),
73
- // Slate grey
74
- debug: chalk.rgb(34, 139, 34),
75
- // Forest green
76
- info: chalk.rgb(46, 139, 87),
77
- // Sea green
78
- warn: chalk.rgb(218, 165, 32),
79
- // Golden rod
80
- error: chalk.rgb(139, 69, 19),
81
- // Saddle brown
82
- fatal: chalk.bgRgb(139, 69, 19).white
83
- // Brown background with white text
84
- },
85
- logIdColor: chalk.rgb(101, 115, 126),
86
- dataValueColor: chalk.rgb(0, 0, 0),
87
- dataKeyColor: chalk.rgb(34, 139, 34)
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
- var pastel = {
90
- colors: {
91
- trace: chalk.rgb(200, 200, 200),
92
- // Light grey
93
- debug: chalk.rgb(173, 216, 230),
94
- // Light blue
95
- info: chalk.rgb(144, 238, 144),
96
- // Light green
97
- warn: chalk.rgb(255, 218, 185),
98
- // Peach
99
- error: chalk.rgb(255, 182, 193),
100
- // Light pink
101
- fatal: chalk.bgRgb(255, 182, 193).rgb(105, 105, 105)
102
- // Light pink bg with dim grey text
103
- },
104
- logIdColor: chalk.rgb(200, 200, 200),
105
- dataValueColor: chalk.rgb(105, 105, 105),
106
- dataKeyColor: chalk.rgb(173, 216, 230)
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
- // src/vendor/prettyjson.js
110
- import chalk2 from "chalk";
111
-
112
- // src/vendor/utils.js
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
- return new Array(numSpaces + 1).join(" ");
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
- var maxWidth = 0;
118
- Object.getOwnPropertyNames(input).forEach((key) => {
119
- if (input[key] === void 0) {
120
- return;
121
- }
122
- maxWidth = Math.max(maxWidth, key.length);
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
- if (typeof isoString !== "string") {
128
- return false;
129
- }
130
- if (!/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?$/.test(isoString)) {
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
- // src/vendor/prettyjson.js
138
- var conflictChars = /[^\w\s\n\r\v\t.,]/i;
139
- var isPrintable = (input, options) => input !== void 0 || options.renderUndefined;
140
- var isSerializable = (input, onlyPrimitives, options) => {
141
- if (typeof input === "boolean" || typeof input === "number" || typeof input === "function" || input === null || input === void 0 || input instanceof Date) {
142
- return true;
143
- }
144
- if (typeof input === "string" && input.indexOf("\n") === -1) {
145
- return true;
146
- }
147
- if (options.inlineArrays && !onlyPrimitives) {
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
- var getColorRenderer = (colorFn, options) => {
155
- if (options.noColor) {
156
- return (text) => text;
157
- }
158
- if (typeof colorFn !== "function") {
159
- return (text) => text;
160
- }
161
- return colorFn;
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
- var addColorToData = (input, options) => {
164
- if (options.noColor) {
165
- return input;
166
- }
167
- if (input instanceof Date) {
168
- return getColorRenderer(options.dateColor, options)(input.toISOString());
169
- }
170
- if (typeof input === "string") {
171
- if (isIsoStringDate(input)) {
172
- return getColorRenderer(options.dateColor, options)(input);
173
- }
174
- return getColorRenderer(options.stringColor, options)(input);
175
- }
176
- const sInput = `${input}`;
177
- if (typeof input === "boolean") {
178
- return getColorRenderer(options.booleanColor, options)(sInput);
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
- var colorMultilineString = (options, line) => getColorRenderer(options.multilineStringColor, options)(line);
198
- var indentLines = (string, spaces, options) => {
199
- let lines = string.split("\n");
200
- lines = lines.map((line) => indent(spaces) + colorMultilineString(options, line));
201
- return lines.join("\n");
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
- var renderToArray = (data, options, indentation) => {
204
- if (typeof data === "string" && data.match(conflictChars) && options.escape) {
205
- data = JSON.stringify(data);
206
- }
207
- if (!isPrintable(data, options)) {
208
- return [];
209
- }
210
- if (isSerializable(data, false, options)) {
211
- return [indent(indentation) + addColorToData(data, options)];
212
- }
213
- if (typeof data === "string") {
214
- return [
215
- indent(indentation) + colorMultilineString(options, '"""'),
216
- indentLines(data, indentation + options.defaultIndentation, options),
217
- indent(indentation) + colorMultilineString(options, '"""')
218
- ];
219
- }
220
- if (Array.isArray(data)) {
221
- if (data.length === 0) {
222
- return [indent(indentation) + options.emptyArrayMsg];
223
- }
224
- if (options.collapseArrays && data.length > 0) {
225
- return [`${indent(indentation)}[... ${data.length} items]`];
226
- }
227
- const outputArray = [];
228
- data.forEach((element) => {
229
- if (!isPrintable(element, options)) {
230
- return;
231
- }
232
- let line = "- ";
233
- line = getColorRenderer(options.dashColor, options)(line);
234
- line = indent(indentation) + line;
235
- if (isSerializable(element, false, options)) {
236
- line += renderToArray(element, options, 0)[0];
237
- outputArray.push(line);
238
- } else {
239
- outputArray.push(line);
240
- outputArray.push.apply(outputArray, renderToArray(element, options, indentation + options.defaultIndentation));
241
- }
242
- });
243
- return outputArray;
244
- }
245
- if (data instanceof Error) {
246
- return renderToArray(
247
- {
248
- message: data.message,
249
- stack: data.stack.split("\n")
250
- },
251
- options,
252
- indentation
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
- var validateOptionsAndSetDefaults = (options) => {
277
- options = options || {};
278
- options.emptyArrayMsg = options.emptyArrayMsg || "(empty array)";
279
- options.keysColor = options.keysColor || chalk2.green;
280
- options.dashColor = options.dashColor || chalk2.green;
281
- options.booleanColor = options.booleanColor || chalk2.cyan;
282
- options.nullUndefinedColor = options.nullUndefinedColor || chalk2.grey;
283
- options.numberColor = options.numberColor || chalk2.blue;
284
- options.positiveNumberColor = options.positiveNumberColor || options.numberColor;
285
- options.negativeNumberColor = options.negativeNumberColor || options.numberColor;
286
- options.dateColor = options.dateColor || chalk2.magenta;
287
- options.defaultIndentation = options.defaultIndentation || 2;
288
- options.noColor = !!options.noColor;
289
- options.noAlign = !!options.noAlign;
290
- options.escape = !!options.escape;
291
- options.renderUndefined = !!options.renderUndefined;
292
- options.collapseArrays = !!options.collapseArrays;
293
- options.stringColor = options.stringColor || null;
294
- options.multilineStringColor = options.multilineStringColor || options.stringColor || null;
295
- return options;
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
- indentation = indentation || 0;
299
- options = validateOptionsAndSetDefaults(options);
300
- return renderToArray(data, options, indentation).join("\n");
333
+ indentation = indentation || 0;
334
+ options = validateOptionsAndSetDefaults(options);
335
+ return renderToArray(data, options, indentation).join("\n");
301
336
  }
302
337
 
303
- // src/views/utils.ts
304
- import chalk3 from "chalk";
305
- import { format } from "date-fns";
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
- let formattedTime;
308
- if (typeof timestampFormat === "function") {
309
- formattedTime = timestampFormat(timestamp);
310
- } else {
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
- const levelLower = level.toLowerCase();
318
- switch (levelLower) {
319
- case "trace":
320
- return colors.trace || chalk3.white;
321
- case "debug":
322
- return colors.debug || chalk3.white;
323
- case "info":
324
- return colors.info || chalk3.white;
325
- case "warn":
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
- if (typeof value === "string") return value;
337
- if (typeof value === "number" || typeof value === "boolean") return value.toString();
338
- if (value === null) return "null";
339
- if (value === void 0) return "undefined";
340
- if (Array.isArray(value)) return expanded ? JSON.stringify(value) : collapseArrays ? "[...]" : value.toString();
341
- if (typeof value === "object") return expanded ? JSON.stringify(value) : "{...}";
342
- return value.toString();
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
- if (!data) return "";
346
- const pairs = [];
347
- const traverse = (obj, prefix = "", depth = 0) => {
348
- if (!expanded && depth >= maxDepth) return;
349
- for (const [key, value] of Object.entries(obj)) {
350
- const fullKey = prefix ? `${prefix}.${key}` : key;
351
- if (value && typeof value === "object" && !Array.isArray(value)) {
352
- if (expanded) {
353
- pairs.push(`${config.dataKeyColor(fullKey)}=${config.dataValueColor(JSON.stringify(value))}`);
354
- } else {
355
- traverse(value, fullKey, depth + 1);
356
- }
357
- } else {
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
- // src/views/SimpleView.ts
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
- config;
372
- viewMode;
373
- maxInlineDepth;
374
- showLogId;
375
- timestampFormat;
376
- collapseArrays;
377
- flattenNestedObjects;
378
- runtime;
379
- includeDataInBrowserConsole;
380
- constructor(config) {
381
- this.config = config;
382
- this.viewMode = config.viewMode;
383
- this.maxInlineDepth = config.maxInlineDepth;
384
- this.showLogId = config.showLogId;
385
- this.timestampFormat = config.timestampFormat;
386
- this.collapseArrays = config.collapseArrays !== false;
387
- this.flattenNestedObjects = config.flattenNestedObjects !== false;
388
- this.runtime = config.runtime;
389
- this.includeDataInBrowserConsole = config.includeDataInBrowserConsole || false;
390
- }
391
- getConfig() {
392
- return this.config;
393
- }
394
- getViewMode() {
395
- return this.viewMode;
396
- }
397
- /**
398
- * Writes a message to the appropriate output based on runtime
399
- */
400
- writeMessage(message, level, data) {
401
- if (this.runtime === "node") {
402
- process?.stdout?.write?.(`${message}
403
- `);
404
- } else {
405
- const shouldIncludeData = this.includeDataInBrowserConsole && data !== void 0;
406
- switch (level) {
407
- case "trace":
408
- if (shouldIncludeData) {
409
- console.debug(message, data);
410
- } else {
411
- console.debug(message);
412
- }
413
- break;
414
- case "debug":
415
- if (shouldIncludeData) {
416
- console.debug(message, data);
417
- } else {
418
- console.debug(message);
419
- }
420
- break;
421
- case "info":
422
- if (shouldIncludeData) {
423
- console.info(message, data);
424
- } else {
425
- console.info(message);
426
- }
427
- break;
428
- case "warn":
429
- if (shouldIncludeData) {
430
- console.warn(message, data);
431
- } else {
432
- console.warn(message);
433
- }
434
- break;
435
- case "error":
436
- case "fatal":
437
- if (shouldIncludeData) {
438
- console.error(message, data);
439
- } else {
440
- console.error(message);
441
- }
442
- break;
443
- default:
444
- if (shouldIncludeData) {
445
- console.log(message, data);
446
- } else {
447
- console.log(message);
448
- }
449
- break;
450
- }
451
- }
452
- }
453
- /**
454
- * Renders a single log entry based on the current view mode
455
- */
456
- renderLogLine(entry) {
457
- const levelColor = getLevelColor(entry.level, this.config.config.colors);
458
- const chevron = levelColor(`\u25B6 ${entry.level.toUpperCase()} `);
459
- const message = entry.message || "(no message)";
460
- const timestamp = formatTimestamp(entry.timestamp, this.config.config.logIdColor, this.timestampFormat);
461
- const parsedData = entry.data ? JSON.parse(entry.data) : void 0;
462
- switch (this.viewMode) {
463
- case "message-only": {
464
- const condensedLine = `${timestamp} ${chevron}${message}`;
465
- this.writeMessage(condensedLine, entry.level, parsedData);
466
- break;
467
- }
468
- case "inline": {
469
- const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
470
- const fullData = entry.data ? formatInlineData(
471
- JSON.parse(entry.data),
472
- this.config.config,
473
- this.maxInlineDepth,
474
- !this.flattenNestedObjects,
475
- this.collapseArrays
476
- ) : "";
477
- const expandedLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}${fullData ? ` ${fullData}` : ""}`;
478
- this.writeMessage(expandedLine, entry.level, parsedData);
479
- break;
480
- }
481
- case "expanded": {
482
- const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
483
- const firstLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}`;
484
- this.writeMessage(firstLine, entry.level, parsedData);
485
- if (entry.data) {
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
- // src/SimplePrettyTerminalTransport.ts
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
- /** Handles rendering and formatting of logs */
522
- renderer;
523
- /** Configuration options */
524
- config;
525
- /**
526
- * Creates a new SimplePrettyTerminalTransport instance.
527
- *
528
- * @param config - Configuration options for the transport
529
- */
530
- constructor(config) {
531
- super(config);
532
- this.config = config;
533
- if (config.enabled === false) {
534
- return;
535
- }
536
- const maxInlineDepth = config.maxInlineDepth || 4;
537
- const theme = config.theme || moonlight;
538
- const viewMode = config.viewMode || "inline";
539
- const showLogId = config.showLogId || false;
540
- const timestampFormat = config.timestampFormat || "HH:mm:ss.SSS";
541
- const collapseArrays = config.collapseArrays !== false;
542
- const flattenNestedObjects = config.flattenNestedObjects !== false;
543
- const runtime = config.runtime;
544
- const includeDataInBrowserConsole = config.includeDataInBrowserConsole || false;
545
- const viewConfig = {
546
- colors: {
547
- trace: chalk4.gray,
548
- // Lowest level, used for verbose output
549
- debug: chalk4.blue,
550
- // Debug information
551
- info: chalk4.green,
552
- // Normal operation
553
- warn: chalk4.yellow,
554
- // Warning conditions
555
- error: chalk4.red,
556
- // Error conditions
557
- fatal: chalk4.bgRed.white,
558
- // Critical errors
559
- ...theme.colors
560
- },
561
- logIdColor: theme.logIdColor || chalk4.dim,
562
- dataValueColor: theme.dataValueColor || chalk4.white,
563
- dataKeyColor: theme.dataKeyColor || chalk4.dim
564
- };
565
- this.renderer = new SimpleView({
566
- viewMode,
567
- maxInlineDepth,
568
- showLogId,
569
- timestampFormat,
570
- collapseArrays,
571
- flattenNestedObjects,
572
- runtime,
573
- includeDataInBrowserConsole,
574
- config: viewConfig
575
- });
576
- }
577
- /**
578
- * Generates a random ID for each log entry.
579
- * Uses base36 encoding for compact, readable IDs.
580
- *
581
- * @returns A 6-character string ID
582
- * @example
583
- * "a1b2c3" // Example generated ID
584
- */
585
- generateId() {
586
- return Math.random().toString(36).substring(2, 8);
587
- }
588
- /**
589
- * Main transport method that receives logs from LogLayer.
590
- * This method is called for each log event and handles:
591
- * - Generating a unique ID for the log
592
- * - Converting the log data to a storable format
593
- * - Rendering the log using the SimpleView renderer
594
- *
595
- * @param logLevel - The severity level of the log
596
- * @param messages - Array of message strings to be joined
597
- * @param data - Additional structured data to be logged
598
- * @param hasData - Whether the log includes additional data
599
- * @returns The original messages array
600
- */
601
- shipToLogger({ logLevel, messages, data, hasData }) {
602
- if (this.config.enabled === false) {
603
- return messages;
604
- }
605
- const entry = {
606
- id: this.generateId(),
607
- timestamp: Date.now(),
608
- level: logLevel,
609
- message: messages.join(" "),
610
- data: hasData ? JSON.stringify(data) : null
611
- };
612
- this.renderer.renderLogLine(entry);
613
- return messages;
614
- }
615
- /**
616
- * Changes the view mode for log display.
617
- *
618
- * @param viewMode - The new view mode to use
619
- */
620
- setViewMode(viewMode) {
621
- if (this.config.enabled === false) {
622
- return;
623
- }
624
- const theme = this.config.theme || moonlight;
625
- const runtime = this.config.runtime;
626
- const viewConfig = {
627
- colors: {
628
- trace: chalk4.gray,
629
- debug: chalk4.blue,
630
- info: chalk4.green,
631
- warn: chalk4.yellow,
632
- error: chalk4.red,
633
- fatal: chalk4.bgRed.white,
634
- ...theme.colors
635
- },
636
- logIdColor: theme.logIdColor || chalk4.dim,
637
- dataValueColor: theme.dataValueColor || chalk4.white,
638
- dataKeyColor: theme.dataKeyColor || chalk4.dim
639
- };
640
- this.renderer = new SimpleView({
641
- viewMode,
642
- maxInlineDepth: this.config.maxInlineDepth || 4,
643
- showLogId: this.config.showLogId || false,
644
- timestampFormat: this.config.timestampFormat || "HH:mm:ss.SSS",
645
- collapseArrays: this.config.collapseArrays !== false,
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
- // src/index.ts
663
- export * from "chalk";
676
+ //#endregion
677
+ //#region src/index.ts
664
678
  function getSimplePrettyTerminal(config) {
665
- return new SimplePrettyTerminalTransport(config);
679
+ return new SimplePrettyTerminalTransport(config);
666
680
  }
667
- export {
668
- SimplePrettyTerminalTransport,
669
- getSimplePrettyTerminal,
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