@loglayer/transport-simple-pretty-terminal 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Theo Gravity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @loglayer/transport-simple-pretty-terminal
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@loglayer/transport-simple-pretty-terminal)](https://www.npmjs.com/package/@loglayer/transport-simple-pretty-terminal)
4
+ [![Downloads](https://img.shields.io/npm/dm/@loglayer/transport-simple-pretty-terminal)](https://www.npmjs.com/package/@loglayer/transport-simple-pretty-terminal)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Yes-blue)](https://www.typescriptlang.org/)
6
+
7
+ A transport for the [LogLayer](https://loglayer.dev) logging library that pretty-prints logs printed in the terminal.
8
+
9
+ [Pretty terminal](https://loglayer.dev/transports/pretty-terminal)'s simpler cousin with no interactive features. Designed for use with Next.js and apps running concurrently.
10
+
11
+ ![Simple Pretty Terminal Transport](https://loglayer.dev/images/simple-pretty-terminal/terminal-inline.webp)
12
+
13
+ ## Features
14
+
15
+ - 🎨 **Color-coded Log Levels** - Each log level has distinct colors for quick visual identification
16
+ - 💅 **JSON Pretty Printing** - Beautifully formatted structured data with syntax highlighting
17
+ - 🎭 **Configurable Themes** - Choose from pre-built themes or customize your own colors
18
+
19
+ ## Installation
20
+
21
+ Visit the [Simple Pretty Terminal docs](https://loglayer.dev/transports/simple-pretty-terminal) for installation and usage.
package/dist/index.cjs ADDED
@@ -0,0 +1,625 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }// src/SimplePrettyTerminalTransport.ts
2
+ var _transport = require('@loglayer/transport');
3
+ var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); _createStarExport(_chalk);
4
+
5
+ // src/themes.ts
6
+
7
+ var moonlight = {
8
+ colors: {
9
+ trace: _chalk2.default.rgb(114, 135, 153),
10
+ // Muted blue-grey for less important info
11
+ debug: _chalk2.default.rgb(130, 170, 255),
12
+ // Soft blue that pops but doesn't strain
13
+ info: _chalk2.default.rgb(195, 232, 141),
14
+ // Sage green for good readability
15
+ warn: _chalk2.default.rgb(255, 203, 107),
16
+ // Warm yellow, less harsh than pure yellow
17
+ error: _chalk2.default.rgb(247, 118, 142),
18
+ // Soft red that stands out without being aggressive
19
+ fatal: _chalk2.default.bgRgb(247, 118, 142).white
20
+ // Inverted soft red for maximum visibility
21
+ },
22
+ logIdColor: _chalk2.default.rgb(84, 98, 117),
23
+ // Darker blue-grey for secondary information
24
+ dataValueColor: _chalk2.default.rgb(209, 219, 231),
25
+ // Light grey-blue for primary content
26
+ dataKeyColor: _chalk2.default.rgb(130, 170, 255)
27
+ // Matching debug blue for consistency
28
+ };
29
+ var sunlight = {
30
+ colors: {
31
+ trace: _chalk2.default.rgb(110, 110, 110),
32
+ // Dark grey for subtle information
33
+ debug: _chalk2.default.rgb(32, 96, 159),
34
+ // Deep blue for strong contrast on white
35
+ info: _chalk2.default.rgb(35, 134, 54),
36
+ // Forest green, easier on the eyes than bright green
37
+ warn: _chalk2.default.rgb(176, 95, 0),
38
+ // Brown-orange for natural warning color
39
+ error: _chalk2.default.rgb(191, 0, 0),
40
+ // Deep red for clear visibility on light backgrounds
41
+ fatal: _chalk2.default.bgRgb(191, 0, 0).white
42
+ // White on deep red for critical issues
43
+ },
44
+ logIdColor: _chalk2.default.rgb(110, 110, 110),
45
+ dataValueColor: _chalk2.default.rgb(0, 0, 0),
46
+ dataKeyColor: _chalk2.default.rgb(32, 96, 159)
47
+ };
48
+ var neon = {
49
+ colors: {
50
+ trace: _chalk2.default.rgb(108, 108, 255),
51
+ // Electric blue
52
+ debug: _chalk2.default.rgb(255, 82, 246),
53
+ // Hot pink
54
+ info: _chalk2.default.rgb(0, 255, 163),
55
+ // Cyber green
56
+ warn: _chalk2.default.rgb(255, 231, 46),
57
+ // Electric yellow
58
+ error: _chalk2.default.rgb(255, 53, 91),
59
+ // Neon red
60
+ fatal: _chalk2.default.bgRgb(255, 53, 91).rgb(0, 255, 163)
61
+ // Neon red bg with cyber green text
62
+ },
63
+ logIdColor: _chalk2.default.rgb(187, 134, 252),
64
+ // Bright purple
65
+ dataValueColor: _chalk2.default.rgb(255, 255, 255),
66
+ // Pure white
67
+ dataKeyColor: _chalk2.default.rgb(0, 255, 240)
68
+ // Cyan
69
+ };
70
+ var nature = {
71
+ colors: {
72
+ trace: _chalk2.default.rgb(101, 115, 126),
73
+ // Slate grey
74
+ debug: _chalk2.default.rgb(34, 139, 34),
75
+ // Forest green
76
+ info: _chalk2.default.rgb(46, 139, 87),
77
+ // Sea green
78
+ warn: _chalk2.default.rgb(218, 165, 32),
79
+ // Golden rod
80
+ error: _chalk2.default.rgb(139, 69, 19),
81
+ // Saddle brown
82
+ fatal: _chalk2.default.bgRgb(139, 69, 19).white
83
+ // Brown background with white text
84
+ },
85
+ logIdColor: _chalk2.default.rgb(101, 115, 126),
86
+ dataValueColor: _chalk2.default.rgb(0, 0, 0),
87
+ dataKeyColor: _chalk2.default.rgb(34, 139, 34)
88
+ };
89
+ var pastel = {
90
+ colors: {
91
+ trace: _chalk2.default.rgb(200, 200, 200),
92
+ // Light grey
93
+ debug: _chalk2.default.rgb(173, 216, 230),
94
+ // Light blue
95
+ info: _chalk2.default.rgb(144, 238, 144),
96
+ // Light green
97
+ warn: _chalk2.default.rgb(255, 218, 185),
98
+ // Peach
99
+ error: _chalk2.default.rgb(255, 182, 193),
100
+ // Light pink
101
+ fatal: _chalk2.default.bgRgb(255, 182, 193).rgb(105, 105, 105)
102
+ // Light pink bg with dim grey text
103
+ },
104
+ logIdColor: _chalk2.default.rgb(200, 200, 200),
105
+ dataValueColor: _chalk2.default.rgb(105, 105, 105),
106
+ dataKeyColor: _chalk2.default.rgb(173, 216, 230)
107
+ };
108
+
109
+ // src/views/SimpleView.ts
110
+ var _wrapansi = require('wrap-ansi'); var _wrapansi2 = _interopRequireDefault(_wrapansi);
111
+
112
+ // src/vendor/prettyjson.js
113
+
114
+
115
+ // src/vendor/utils.js
116
+ function indent(numSpaces) {
117
+ return new Array(numSpaces + 1).join(" ");
118
+ }
119
+ function getMaxIndexLength(input) {
120
+ var maxWidth = 0;
121
+ Object.getOwnPropertyNames(input).forEach((key) => {
122
+ if (input[key] === void 0) {
123
+ return;
124
+ }
125
+ maxWidth = Math.max(maxWidth, key.length);
126
+ });
127
+ return maxWidth;
128
+ }
129
+ function isIsoStringDate(isoString) {
130
+ if (typeof isoString !== "string") {
131
+ return false;
132
+ }
133
+ if (!/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?$/.test(isoString)) {
134
+ return false;
135
+ }
136
+ const testDate = new Date(isoString);
137
+ return !Number.isNaN(testDate.getTime());
138
+ }
139
+
140
+ // src/vendor/prettyjson.js
141
+ var conflictChars = /[^\w\s\n\r\v\t.,]/i;
142
+ var isPrintable = (input, options) => input !== void 0 || options.renderUndefined;
143
+ var isSerializable = (input, onlyPrimitives, options) => {
144
+ if (typeof input === "boolean" || typeof input === "number" || typeof input === "function" || input === null || input === void 0 || input instanceof Date) {
145
+ return true;
146
+ }
147
+ if (typeof input === "string" && input.indexOf("\n") === -1) {
148
+ return true;
149
+ }
150
+ if (options.inlineArrays && !onlyPrimitives) {
151
+ if (Array.isArray(input) && isSerializable(input[0], true, options)) {
152
+ return true;
153
+ }
154
+ }
155
+ return false;
156
+ };
157
+ var getColorRenderer = (colorFn, options) => {
158
+ if (options.noColor) {
159
+ return (text) => text;
160
+ }
161
+ if (typeof colorFn !== "function") {
162
+ return (text) => text;
163
+ }
164
+ return colorFn;
165
+ };
166
+ var addColorToData = (input, options) => {
167
+ if (options.noColor) {
168
+ return input;
169
+ }
170
+ if (input instanceof Date) {
171
+ return getColorRenderer(options.dateColor, options)(input.toISOString());
172
+ }
173
+ if (typeof input === "string") {
174
+ if (isIsoStringDate(input)) {
175
+ return getColorRenderer(options.dateColor, options)(input);
176
+ }
177
+ return getColorRenderer(options.stringColor, options)(input);
178
+ }
179
+ const sInput = `${input}`;
180
+ if (typeof input === "boolean") {
181
+ return getColorRenderer(options.booleanColor, options)(sInput);
182
+ }
183
+ if (input === null || input === void 0) {
184
+ return getColorRenderer(options.nullUndefinedColor, options)(sInput);
185
+ }
186
+ if (typeof input === "number") {
187
+ if (input >= 0) {
188
+ return getColorRenderer(options.positiveNumberColor, options)(sInput);
189
+ }
190
+ return getColorRenderer(options.negativeNumberColor, options)(sInput);
191
+ }
192
+ if (typeof input === "function") {
193
+ return "function() {}";
194
+ }
195
+ if (Array.isArray(input)) {
196
+ return input.join(", ");
197
+ }
198
+ return sInput;
199
+ };
200
+ var colorMultilineString = (options, line) => getColorRenderer(options.multilineStringColor, options)(line);
201
+ var indentLines = (string, spaces, options) => {
202
+ let lines = string.split("\n");
203
+ lines = lines.map((line) => indent(spaces) + colorMultilineString(options, line));
204
+ return lines.join("\n");
205
+ };
206
+ var renderToArray = (data, options, indentation) => {
207
+ if (typeof data === "string" && data.match(conflictChars) && options.escape) {
208
+ data = JSON.stringify(data);
209
+ }
210
+ if (!isPrintable(data, options)) {
211
+ return [];
212
+ }
213
+ if (isSerializable(data, false, options)) {
214
+ return [indent(indentation) + addColorToData(data, options)];
215
+ }
216
+ if (typeof data === "string") {
217
+ return [
218
+ indent(indentation) + colorMultilineString(options, '"""'),
219
+ indentLines(data, indentation + options.defaultIndentation, options),
220
+ indent(indentation) + colorMultilineString(options, '"""')
221
+ ];
222
+ }
223
+ if (Array.isArray(data)) {
224
+ if (data.length === 0) {
225
+ return [indent(indentation) + options.emptyArrayMsg];
226
+ }
227
+ if (options.collapseArrays && data.length > 0) {
228
+ return [`${indent(indentation)}[... ${data.length} items]`];
229
+ }
230
+ const outputArray = [];
231
+ data.forEach((element) => {
232
+ if (!isPrintable(element, options)) {
233
+ return;
234
+ }
235
+ let line = "- ";
236
+ line = getColorRenderer(options.dashColor, options)(line);
237
+ line = indent(indentation) + line;
238
+ if (isSerializable(element, false, options)) {
239
+ line += renderToArray(element, options, 0)[0];
240
+ outputArray.push(line);
241
+ } else {
242
+ outputArray.push(line);
243
+ outputArray.push.apply(outputArray, renderToArray(element, options, indentation + options.defaultIndentation));
244
+ }
245
+ });
246
+ return outputArray;
247
+ }
248
+ if (data instanceof Error) {
249
+ return renderToArray(
250
+ {
251
+ message: data.message,
252
+ stack: data.stack.split("\n")
253
+ },
254
+ options,
255
+ indentation
256
+ );
257
+ }
258
+ const maxIndexLength = options.noAlign ? 0 : getMaxIndexLength(data);
259
+ let key;
260
+ const output = [];
261
+ Object.getOwnPropertyNames(data).forEach((i) => {
262
+ if (!isPrintable(data[i], options)) {
263
+ return;
264
+ }
265
+ key = `${i}: `;
266
+ key = getColorRenderer(options.keysColor, options)(key);
267
+ key = indent(indentation) + key;
268
+ if (isSerializable(data[i], false, options)) {
269
+ const nextIndentation = options.noAlign ? 0 : maxIndexLength - i.length;
270
+ key += renderToArray(data[i], options, nextIndentation)[0];
271
+ output.push(key);
272
+ } else {
273
+ output.push(key);
274
+ output.push.apply(output, renderToArray(data[i], options, indentation + options.defaultIndentation));
275
+ }
276
+ });
277
+ return output;
278
+ };
279
+ var validateOptionsAndSetDefaults = (options) => {
280
+ options = options || {};
281
+ options.emptyArrayMsg = options.emptyArrayMsg || "(empty array)";
282
+ options.keysColor = options.keysColor || _chalk2.default.green;
283
+ options.dashColor = options.dashColor || _chalk2.default.green;
284
+ options.booleanColor = options.booleanColor || _chalk2.default.cyan;
285
+ options.nullUndefinedColor = options.nullUndefinedColor || _chalk2.default.grey;
286
+ options.numberColor = options.numberColor || _chalk2.default.blue;
287
+ options.positiveNumberColor = options.positiveNumberColor || options.numberColor;
288
+ options.negativeNumberColor = options.negativeNumberColor || options.numberColor;
289
+ options.dateColor = options.dateColor || _chalk2.default.magenta;
290
+ options.defaultIndentation = options.defaultIndentation || 2;
291
+ options.noColor = !!options.noColor;
292
+ options.noAlign = !!options.noAlign;
293
+ options.escape = !!options.escape;
294
+ options.renderUndefined = !!options.renderUndefined;
295
+ options.collapseArrays = !!options.collapseArrays;
296
+ options.stringColor = options.stringColor || null;
297
+ options.multilineStringColor = options.multilineStringColor || options.stringColor || null;
298
+ return options;
299
+ };
300
+ function render(data, options, indentation) {
301
+ indentation = indentation || 0;
302
+ options = validateOptionsAndSetDefaults(options);
303
+ return renderToArray(data, options, indentation).join("\n");
304
+ }
305
+
306
+ // src/views/utils.ts
307
+
308
+ var _datefns = require('date-fns');
309
+ function formatTimestamp(timestamp, colorFn, timestampFormat = "HH:mm:ss.SSS") {
310
+ let formattedTime;
311
+ if (typeof timestampFormat === "function") {
312
+ formattedTime = timestampFormat(timestamp);
313
+ } else {
314
+ const date = new Date(timestamp);
315
+ formattedTime = _datefns.format.call(void 0, date, timestampFormat);
316
+ }
317
+ return colorFn(`[${formattedTime}]`);
318
+ }
319
+ function getLevelColor(level, colors) {
320
+ const levelLower = level.toLowerCase();
321
+ switch (levelLower) {
322
+ case "trace":
323
+ return colors.trace || _chalk2.default.white;
324
+ case "debug":
325
+ return colors.debug || _chalk2.default.white;
326
+ case "info":
327
+ return colors.info || _chalk2.default.white;
328
+ case "warn":
329
+ return colors.warn || _chalk2.default.white;
330
+ case "error":
331
+ return colors.error || _chalk2.default.white;
332
+ case "fatal":
333
+ return colors.fatal || _chalk2.default.white;
334
+ default:
335
+ return colors.info || _chalk2.default.white;
336
+ }
337
+ }
338
+ function formatValue(value, expanded = false, collapseArrays = true) {
339
+ if (typeof value === "string") return value;
340
+ if (typeof value === "number" || typeof value === "boolean") return value.toString();
341
+ if (value === null) return "null";
342
+ if (value === void 0) return "undefined";
343
+ if (Array.isArray(value)) return expanded ? JSON.stringify(value) : collapseArrays ? "[...]" : value.toString();
344
+ if (typeof value === "object") return expanded ? JSON.stringify(value) : "{...}";
345
+ return value.toString();
346
+ }
347
+ function formatInlineData(data, config, maxDepth, expanded = false, collapseArrays = true) {
348
+ if (!data) return "";
349
+ const pairs = [];
350
+ const traverse = (obj, prefix = "", depth = 0) => {
351
+ if (!expanded && depth >= maxDepth) return;
352
+ for (const [key, value] of Object.entries(obj)) {
353
+ const fullKey = prefix ? `${prefix}.${key}` : key;
354
+ if (value && typeof value === "object" && !Array.isArray(value)) {
355
+ if (expanded) {
356
+ pairs.push(`${config.dataKeyColor(fullKey)}=${config.dataValueColor(JSON.stringify(value))}`);
357
+ } else {
358
+ traverse(value, fullKey, depth + 1);
359
+ }
360
+ } else {
361
+ pairs.push(
362
+ `${config.dataKeyColor(fullKey)}=${config.dataValueColor(formatValue(value, expanded, collapseArrays))}`
363
+ );
364
+ }
365
+ }
366
+ };
367
+ traverse(data);
368
+ const result = pairs.join(" ");
369
+ return result;
370
+ }
371
+
372
+ // src/views/SimpleView.ts
373
+ var SimpleView = class {
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+ constructor(config) {
383
+ this.config = config;
384
+ this.viewMode = config.viewMode;
385
+ this.maxInlineDepth = config.maxInlineDepth;
386
+ this.showLogId = config.showLogId;
387
+ this.timestampFormat = config.timestampFormat;
388
+ this.collapseArrays = config.collapseArrays !== false;
389
+ this.flattenNestedObjects = config.flattenNestedObjects !== false;
390
+ this.termWidth = process.stdout.columns || 120;
391
+ }
392
+ updateTerminalWidth(width) {
393
+ this.termWidth = width;
394
+ }
395
+ getConfig() {
396
+ return this.config;
397
+ }
398
+ getViewMode() {
399
+ return this.viewMode;
400
+ }
401
+ /**
402
+ * Renders a single log entry based on the current view mode
403
+ */
404
+ renderLogLine(entry) {
405
+ const levelColor = getLevelColor(entry.level, this.config.config.colors);
406
+ const chevron = levelColor(`\u25B6 ${entry.level.toUpperCase()} `);
407
+ const message = entry.message || "(no message)";
408
+ const timestamp = formatTimestamp(entry.timestamp, this.config.config.logIdColor, this.timestampFormat);
409
+ switch (this.viewMode) {
410
+ case "message-only": {
411
+ const condensedLine = `${timestamp} ${chevron}${message}`;
412
+ console.log(_wrapansi2.default.call(void 0, condensedLine, this.termWidth, { hard: true }));
413
+ break;
414
+ }
415
+ case "inline": {
416
+ const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
417
+ const fullData = entry.data ? formatInlineData(
418
+ JSON.parse(entry.data),
419
+ this.config.config,
420
+ this.maxInlineDepth,
421
+ !this.flattenNestedObjects,
422
+ this.collapseArrays
423
+ ) : "";
424
+ const expandedLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}${fullData ? ` ${fullData}` : ""}`;
425
+ console.log(expandedLine);
426
+ break;
427
+ }
428
+ case "expanded": {
429
+ const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
430
+ const firstLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}`;
431
+ console.log(_wrapansi2.default.call(void 0, firstLine, this.termWidth, { hard: true }));
432
+ if (entry.data) {
433
+ const jsonLines = render(JSON.parse(entry.data), {
434
+ defaultIndentation: 2,
435
+ keysColor: this.config.config.dataKeyColor,
436
+ dashColor: this.config.config.dataKeyColor,
437
+ numberColor: this.config.config.dataValueColor,
438
+ stringColor: this.config.config.dataValueColor,
439
+ multilineStringColor: this.config.config.dataValueColor,
440
+ positiveNumberColor: this.config.config.dataValueColor,
441
+ negativeNumberColor: this.config.config.dataValueColor,
442
+ booleanColor: this.config.config.dataValueColor,
443
+ nullUndefinedColor: this.config.config.dataValueColor,
444
+ dateColor: this.config.config.dataValueColor,
445
+ collapseArrays: this.collapseArrays
446
+ }).split("\n");
447
+ for (const line of jsonLines) {
448
+ if (line.trim() === "") {
449
+ console.log(" ");
450
+ } else {
451
+ console.log(` ${line}`);
452
+ }
453
+ }
454
+ }
455
+ break;
456
+ }
457
+ default: {
458
+ const logId = this.showLogId ? this.config.config.logIdColor(`[${entry.id}]`) : "";
459
+ const fullData = entry.data ? formatInlineData(JSON.parse(entry.data), this.config.config, this.maxInlineDepth, true, this.collapseArrays) : "";
460
+ const expandedLine = `${timestamp} ${chevron}${logId ? `${logId} ` : ""}${message}${fullData ? ` ${fullData}` : ""}`;
461
+ console.log(_wrapansi2.default.call(void 0, expandedLine, this.termWidth, { hard: true }));
462
+ break;
463
+ }
464
+ }
465
+ }
466
+ };
467
+
468
+ // src/SimplePrettyTerminalTransport.ts
469
+ var SimplePrettyTerminalTransport = class extends _transport.LoggerlessTransport {
470
+ /** Handles rendering and formatting of logs */
471
+
472
+ /** Configuration options */
473
+
474
+ /** Current terminal width in characters */
475
+
476
+ /**
477
+ * Creates a new SimplePrettyTerminalTransport instance.
478
+ *
479
+ * @param config - Configuration options for the transport
480
+ */
481
+ constructor(config = {}) {
482
+ super(config);
483
+ this.config = config;
484
+ if (config.enabled === false) {
485
+ return;
486
+ }
487
+ const maxInlineDepth = config.maxInlineDepth || 4;
488
+ const theme = config.theme || moonlight;
489
+ const viewMode = config.viewMode || "inline";
490
+ const showLogId = config.showLogId || false;
491
+ const timestampFormat = config.timestampFormat || "HH:mm:ss.SSS";
492
+ const collapseArrays = config.collapseArrays !== false;
493
+ const flattenNestedObjects = config.flattenNestedObjects !== false;
494
+ const viewConfig = {
495
+ colors: {
496
+ trace: _chalk2.default.gray,
497
+ // Lowest level, used for verbose output
498
+ debug: _chalk2.default.blue,
499
+ // Debug information
500
+ info: _chalk2.default.green,
501
+ // Normal operation
502
+ warn: _chalk2.default.yellow,
503
+ // Warning conditions
504
+ error: _chalk2.default.red,
505
+ // Error conditions
506
+ fatal: _chalk2.default.bgRed.white,
507
+ // Critical errors
508
+ ...theme.colors
509
+ },
510
+ logIdColor: theme.logIdColor || _chalk2.default.dim,
511
+ dataValueColor: theme.dataValueColor || _chalk2.default.white,
512
+ dataKeyColor: theme.dataKeyColor || _chalk2.default.dim
513
+ };
514
+ this.termWidth = process.stdout.columns || 80;
515
+ this.renderer = new SimpleView({
516
+ viewMode,
517
+ maxInlineDepth,
518
+ showLogId,
519
+ timestampFormat,
520
+ collapseArrays,
521
+ flattenNestedObjects,
522
+ config: viewConfig
523
+ });
524
+ process.stdout.on("resize", () => {
525
+ this.termWidth = process.stdout.columns || 80;
526
+ this.renderer.updateTerminalWidth(this.termWidth);
527
+ });
528
+ }
529
+ /**
530
+ * Generates a random ID for each log entry.
531
+ * Uses base36 encoding for compact, readable IDs.
532
+ *
533
+ * @returns A 6-character string ID
534
+ * @example
535
+ * "a1b2c3" // Example generated ID
536
+ */
537
+ generateId() {
538
+ return Math.random().toString(36).substring(2, 8);
539
+ }
540
+ /**
541
+ * Main transport method that receives logs from LogLayer.
542
+ * This method is called for each log event and handles:
543
+ * - Generating a unique ID for the log
544
+ * - Converting the log data to a storable format
545
+ * - Rendering the log using the SimpleView renderer
546
+ *
547
+ * @param logLevel - The severity level of the log
548
+ * @param messages - Array of message strings to be joined
549
+ * @param data - Additional structured data to be logged
550
+ * @param hasData - Whether the log includes additional data
551
+ * @returns The original messages array
552
+ */
553
+ shipToLogger({ logLevel, messages, data, hasData }) {
554
+ if (this.config.enabled === false) {
555
+ return messages;
556
+ }
557
+ const entry = {
558
+ id: this.generateId(),
559
+ timestamp: Date.now(),
560
+ level: logLevel,
561
+ message: messages.join(" "),
562
+ data: hasData ? JSON.stringify(data) : null
563
+ };
564
+ this.renderer.renderLogLine(entry);
565
+ return messages;
566
+ }
567
+ /**
568
+ * Changes the view mode for log display.
569
+ *
570
+ * @param viewMode - The new view mode to use
571
+ */
572
+ setViewMode(viewMode) {
573
+ if (this.config.enabled === false) {
574
+ return;
575
+ }
576
+ const theme = this.config.theme || moonlight;
577
+ const viewConfig = {
578
+ colors: {
579
+ trace: _chalk2.default.gray,
580
+ debug: _chalk2.default.blue,
581
+ info: _chalk2.default.green,
582
+ warn: _chalk2.default.yellow,
583
+ error: _chalk2.default.red,
584
+ fatal: _chalk2.default.bgRed.white,
585
+ ...theme.colors
586
+ },
587
+ logIdColor: theme.logIdColor || _chalk2.default.dim,
588
+ dataValueColor: theme.dataValueColor || _chalk2.default.white,
589
+ dataKeyColor: theme.dataKeyColor || _chalk2.default.dim
590
+ };
591
+ this.renderer = new SimpleView({
592
+ viewMode,
593
+ maxInlineDepth: this.config.maxInlineDepth || 4,
594
+ showLogId: this.config.showLogId || false,
595
+ timestampFormat: this.config.timestampFormat || "HH:mm:ss.SSS",
596
+ collapseArrays: this.config.collapseArrays !== false,
597
+ flattenNestedObjects: this.config.flattenNestedObjects !== false,
598
+ config: viewConfig
599
+ });
600
+ }
601
+ /**
602
+ * Gets the current view mode.
603
+ *
604
+ * @returns The current view mode
605
+ */
606
+ getViewMode() {
607
+ return this.renderer.getViewMode();
608
+ }
609
+ };
610
+
611
+ // src/index.ts
612
+
613
+ function getSimplePrettyTerminal(config = {}) {
614
+ return new SimplePrettyTerminalTransport(config);
615
+ }
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+ exports.SimplePrettyTerminalTransport = SimplePrettyTerminalTransport; exports.getSimplePrettyTerminal = getSimplePrettyTerminal; exports.moonlight = moonlight; exports.nature = nature; exports.neon = neon; exports.pastel = pastel; exports.sunlight = sunlight;
625
+ //# sourceMappingURL=index.cjs.map