@socketsecurity/lib 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/arrays.d.ts +143 -0
- package/dist/arrays.js.map +2 -2
- package/dist/fs.d.ts +595 -23
- package/dist/fs.js.map +2 -2
- package/dist/git.d.ts +488 -41
- package/dist/git.js.map +2 -2
- package/dist/github.d.ts +361 -12
- package/dist/github.js.map +2 -2
- package/dist/http-request.d.ts +463 -4
- package/dist/http-request.js.map +2 -2
- package/dist/json.d.ts +177 -4
- package/dist/json.js.map +2 -2
- package/dist/logger.d.ts +822 -67
- package/dist/logger.js +653 -46
- package/dist/logger.js.map +2 -2
- package/dist/objects.d.ts +386 -10
- package/dist/objects.js.map +2 -2
- package/dist/path.d.ts +270 -6
- package/dist/path.js.map +2 -2
- package/dist/promises.d.ts +432 -27
- package/dist/promises.js.map +2 -2
- package/dist/spawn.d.ts +239 -12
- package/dist/spawn.js.map +2 -2
- package/dist/spinner.d.ts +260 -20
- package/dist/spinner.js +201 -63
- package/dist/spinner.js.map +2 -2
- package/dist/stdio/clear.d.ts +130 -9
- package/dist/stdio/clear.js.map +2 -2
- package/dist/stdio/divider.d.ts +106 -10
- package/dist/stdio/divider.js +10 -0
- package/dist/stdio/divider.js.map +2 -2
- package/dist/stdio/footer.d.ts +70 -3
- package/dist/stdio/footer.js.map +2 -2
- package/dist/stdio/header.d.ts +93 -12
- package/dist/stdio/header.js.map +2 -2
- package/dist/stdio/mask.d.ts +82 -14
- package/dist/stdio/mask.js +25 -4
- package/dist/stdio/mask.js.map +2 -2
- package/dist/stdio/progress.d.ts +112 -15
- package/dist/stdio/progress.js +43 -3
- package/dist/stdio/progress.js.map +2 -2
- package/dist/stdio/prompts.d.ts +95 -5
- package/dist/stdio/prompts.js.map +2 -2
- package/dist/stdio/stderr.d.ts +114 -11
- package/dist/stdio/stderr.js.map +2 -2
- package/dist/stdio/stdout.d.ts +107 -11
- package/dist/stdio/stdout.js.map +2 -2
- package/dist/strings.d.ts +357 -28
- package/dist/strings.js.map +2 -2
- package/dist/validation/json-parser.d.ts +226 -7
- package/dist/validation/json-parser.js.map +2 -2
- package/dist/validation/types.d.ts +114 -8
- package/dist/validation/types.js.map +1 -1
- package/package.json +1 -1
package/dist/logger.js
CHANGED
|
@@ -135,6 +135,14 @@ const incLogCallCountSymbol = Symbol.for("logger.logCallCount++");
|
|
|
135
135
|
const kGroupIndentationWidthSymbol = consoleSymbols.find((s) => s.label === "kGroupIndentWidth") ?? Symbol("kGroupIndentWidth");
|
|
136
136
|
const lastWasBlankSymbol = Symbol.for("logger.lastWasBlank");
|
|
137
137
|
class Logger {
|
|
138
|
+
/**
|
|
139
|
+
* Static reference to log symbols for convenience.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* console.log(`${Logger.LOG_SYMBOLS.success} Done`)
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
138
146
|
static LOG_SYMBOLS = LOG_SYMBOLS;
|
|
139
147
|
#parent;
|
|
140
148
|
#boundStream;
|
|
@@ -146,6 +154,27 @@ class Logger {
|
|
|
146
154
|
#logCallCount = 0;
|
|
147
155
|
#constructorArgs;
|
|
148
156
|
#options;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a new Logger instance.
|
|
159
|
+
*
|
|
160
|
+
* When called without arguments, creates a logger using the default
|
|
161
|
+
* `process.stdout` and `process.stderr` streams. Can accept custom
|
|
162
|
+
* console constructor arguments for advanced use cases.
|
|
163
|
+
*
|
|
164
|
+
* @param args - Optional console constructor arguments
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Default logger
|
|
169
|
+
* const logger = new Logger()
|
|
170
|
+
*
|
|
171
|
+
* // Custom streams (advanced)
|
|
172
|
+
* const customLogger = new Logger({
|
|
173
|
+
* stdout: customWritableStream,
|
|
174
|
+
* stderr: customErrorStream
|
|
175
|
+
* })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
149
178
|
constructor(...args) {
|
|
150
179
|
this.#constructorArgs = args;
|
|
151
180
|
const options = args["0"];
|
|
@@ -168,8 +197,25 @@ class Logger {
|
|
|
168
197
|
}
|
|
169
198
|
}
|
|
170
199
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
200
|
+
* Gets a logger instance bound exclusively to stderr.
|
|
201
|
+
*
|
|
202
|
+
* All logging operations on this instance will write to stderr only.
|
|
203
|
+
* Indentation is tracked separately from stdout. The instance is
|
|
204
|
+
* cached and reused on subsequent accesses.
|
|
205
|
+
*
|
|
206
|
+
* @returns A logger instance bound to stderr
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* // Write errors to stderr
|
|
211
|
+
* logger.stderr.error('Configuration invalid')
|
|
212
|
+
* logger.stderr.warn('Using fallback settings')
|
|
213
|
+
*
|
|
214
|
+
* // Indent only affects stderr
|
|
215
|
+
* logger.stderr.indent()
|
|
216
|
+
* logger.stderr.error('Nested error details')
|
|
217
|
+
* logger.stderr.dedent()
|
|
218
|
+
* ```
|
|
173
219
|
*/
|
|
174
220
|
get stderr() {
|
|
175
221
|
if (!this.#stderrLogger) {
|
|
@@ -182,8 +228,25 @@ class Logger {
|
|
|
182
228
|
return this.#stderrLogger;
|
|
183
229
|
}
|
|
184
230
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
231
|
+
* Gets a logger instance bound exclusively to stdout.
|
|
232
|
+
*
|
|
233
|
+
* All logging operations on this instance will write to stdout only.
|
|
234
|
+
* Indentation is tracked separately from stderr. The instance is
|
|
235
|
+
* cached and reused on subsequent accesses.
|
|
236
|
+
*
|
|
237
|
+
* @returns A logger instance bound to stdout
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* // Write normal output to stdout
|
|
242
|
+
* logger.stdout.log('Processing started')
|
|
243
|
+
* logger.stdout.log('Items processed: 42')
|
|
244
|
+
*
|
|
245
|
+
* // Indent only affects stdout
|
|
246
|
+
* logger.stdout.indent()
|
|
247
|
+
* logger.stdout.log('Detailed output')
|
|
248
|
+
* logger.stdout.dedent()
|
|
249
|
+
* ```
|
|
187
250
|
*/
|
|
188
251
|
get stdout() {
|
|
189
252
|
if (!this.#stdoutLogger) {
|
|
@@ -283,27 +346,65 @@ class Logger {
|
|
|
283
346
|
return this;
|
|
284
347
|
}
|
|
285
348
|
/**
|
|
286
|
-
*
|
|
349
|
+
* Gets the total number of log calls made on this logger instance.
|
|
350
|
+
*
|
|
351
|
+
* Tracks all logging method calls including `log()`, `error()`, `warn()`,
|
|
352
|
+
* `success()`, `fail()`, etc. Useful for testing and monitoring logging activity.
|
|
353
|
+
*
|
|
354
|
+
* @returns The number of times logging methods have been called
|
|
355
|
+
*
|
|
356
|
+
* @example
|
|
357
|
+
* ```typescript
|
|
358
|
+
* logger.log('Message 1')
|
|
359
|
+
* logger.error('Message 2')
|
|
360
|
+
* console.log(logger.logCallCount) // 2
|
|
361
|
+
* ```
|
|
287
362
|
*/
|
|
288
363
|
get logCallCount() {
|
|
289
364
|
return this.#logCallCount;
|
|
290
365
|
}
|
|
291
366
|
/**
|
|
292
|
-
*
|
|
367
|
+
* Increments the internal log call counter.
|
|
368
|
+
*
|
|
369
|
+
* This is called automatically by logging methods and should not
|
|
370
|
+
* be called directly in normal usage.
|
|
371
|
+
*
|
|
372
|
+
* @returns The logger instance for chaining
|
|
293
373
|
*/
|
|
294
374
|
[incLogCallCountSymbol]() {
|
|
295
375
|
this.#logCallCount += 1;
|
|
296
376
|
return this;
|
|
297
377
|
}
|
|
298
378
|
/**
|
|
299
|
-
*
|
|
379
|
+
* Sets whether the last logged line was blank.
|
|
380
|
+
*
|
|
381
|
+
* Used internally to track blank lines and prevent duplicate spacing.
|
|
382
|
+
* This is called automatically by logging methods.
|
|
383
|
+
*
|
|
384
|
+
* @param value - Whether the last line was blank
|
|
385
|
+
* @returns The logger instance for chaining
|
|
300
386
|
*/
|
|
301
387
|
[lastWasBlankSymbol](value) {
|
|
302
388
|
this.#lastWasBlank = !!value;
|
|
303
389
|
return this;
|
|
304
390
|
}
|
|
305
391
|
/**
|
|
306
|
-
*
|
|
392
|
+
* Logs an assertion failure message if the value is falsy.
|
|
393
|
+
*
|
|
394
|
+
* Works like `console.assert()` but returns the logger for chaining.
|
|
395
|
+
* If the value is truthy, nothing is logged. If falsy, logs an error
|
|
396
|
+
* message with an assertion failure.
|
|
397
|
+
*
|
|
398
|
+
* @param value - The value to test
|
|
399
|
+
* @param message - Optional message and additional arguments to log
|
|
400
|
+
* @returns The logger instance for chaining
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* logger.assert(true, 'This will not log')
|
|
405
|
+
* logger.assert(false, 'Assertion failed: value is false')
|
|
406
|
+
* logger.assert(items.length > 0, 'No items found')
|
|
407
|
+
* ```
|
|
307
408
|
*/
|
|
308
409
|
assert(value, ...message) {
|
|
309
410
|
const con = privateConsole.get(this);
|
|
@@ -312,8 +413,23 @@ class Logger {
|
|
|
312
413
|
return value ? this : this[incLogCallCountSymbol]();
|
|
313
414
|
}
|
|
314
415
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
416
|
+
* Clears the visible terminal screen.
|
|
417
|
+
*
|
|
418
|
+
* Only available on the main logger instance, not on stream-bound instances
|
|
419
|
+
* (`.stderr` or `.stdout`). Resets the log call count and blank line tracking
|
|
420
|
+
* if the output is a TTY.
|
|
421
|
+
*
|
|
422
|
+
* @returns The logger instance for chaining
|
|
423
|
+
* @throws {Error} If called on a stream-bound logger instance
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* logger.log('Some output')
|
|
428
|
+
* logger.clearVisible() // Screen is now clear
|
|
429
|
+
*
|
|
430
|
+
* // Error: Can't call on stream-bound instance
|
|
431
|
+
* logger.stderr.clearVisible() // throws
|
|
432
|
+
* ```
|
|
317
433
|
*/
|
|
318
434
|
clearVisible() {
|
|
319
435
|
if (this.#boundStream) {
|
|
@@ -331,7 +447,21 @@ class Logger {
|
|
|
331
447
|
return this;
|
|
332
448
|
}
|
|
333
449
|
/**
|
|
334
|
-
*
|
|
450
|
+
* Increments and logs a counter for the given label.
|
|
451
|
+
*
|
|
452
|
+
* Each unique label maintains its own counter. Works like `console.count()`.
|
|
453
|
+
*
|
|
454
|
+
* @param label - Optional label for the counter
|
|
455
|
+
* @default 'default'
|
|
456
|
+
* @returns The logger instance for chaining
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* logger.count('requests') // requests: 1
|
|
461
|
+
* logger.count('requests') // requests: 2
|
|
462
|
+
* logger.count('errors') // errors: 1
|
|
463
|
+
* logger.count() // default: 1
|
|
464
|
+
* ```
|
|
335
465
|
*/
|
|
336
466
|
count(label) {
|
|
337
467
|
const con = privateConsole.get(this);
|
|
@@ -340,7 +470,26 @@ class Logger {
|
|
|
340
470
|
return this[incLogCallCountSymbol]();
|
|
341
471
|
}
|
|
342
472
|
/**
|
|
343
|
-
*
|
|
473
|
+
* Creates a task that logs start and completion messages automatically.
|
|
474
|
+
*
|
|
475
|
+
* Returns a task object with a `run()` method that executes the provided
|
|
476
|
+
* function and logs "Starting task: {name}" before execution and
|
|
477
|
+
* "Completed task: {name}" after completion.
|
|
478
|
+
*
|
|
479
|
+
* @param name - The name of the task
|
|
480
|
+
* @returns A task object with a `run()` method
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* const task = logger.createTask('Database Migration')
|
|
485
|
+
* const result = task.run(() => {
|
|
486
|
+
* // Logs: "Starting task: Database Migration"
|
|
487
|
+
* migrateDatabase()
|
|
488
|
+
* return 'success'
|
|
489
|
+
* // Logs: "Completed task: Database Migration"
|
|
490
|
+
* })
|
|
491
|
+
* console.log(result) // 'success'
|
|
492
|
+
* ```
|
|
344
493
|
*/
|
|
345
494
|
createTask(name) {
|
|
346
495
|
return {
|
|
@@ -353,9 +502,33 @@ class Logger {
|
|
|
353
502
|
};
|
|
354
503
|
}
|
|
355
504
|
/**
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
505
|
+
* Decreases the indentation level by removing spaces from the prefix.
|
|
506
|
+
*
|
|
507
|
+
* When called on the main logger, affects both stderr and stdout indentation.
|
|
508
|
+
* When called on a stream-bound logger (`.stderr` or `.stdout`), affects
|
|
509
|
+
* only that stream's indentation.
|
|
510
|
+
*
|
|
511
|
+
* @param spaces - Number of spaces to remove from indentation
|
|
512
|
+
* @default 2
|
|
513
|
+
* @returns The logger instance for chaining
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```typescript
|
|
517
|
+
* logger.indent()
|
|
518
|
+
* logger.log('Indented')
|
|
519
|
+
* logger.dedent()
|
|
520
|
+
* logger.log('Back to normal')
|
|
521
|
+
*
|
|
522
|
+
* // Remove custom amount
|
|
523
|
+
* logger.indent(4)
|
|
524
|
+
* logger.log('Four spaces')
|
|
525
|
+
* logger.dedent(4)
|
|
526
|
+
*
|
|
527
|
+
* // Stream-specific dedent
|
|
528
|
+
* logger.stdout.indent()
|
|
529
|
+
* logger.stdout.log('Indented stdout')
|
|
530
|
+
* logger.stdout.dedent()
|
|
531
|
+
* ```
|
|
359
532
|
*/
|
|
360
533
|
dedent(spaces = 2) {
|
|
361
534
|
if (this.#boundStream) {
|
|
@@ -370,7 +543,22 @@ class Logger {
|
|
|
370
543
|
return this;
|
|
371
544
|
}
|
|
372
545
|
/**
|
|
373
|
-
*
|
|
546
|
+
* Displays an object's properties in a formatted way.
|
|
547
|
+
*
|
|
548
|
+
* Works like `console.dir()` with customizable options for depth,
|
|
549
|
+
* colors, etc. Useful for inspecting complex objects.
|
|
550
|
+
*
|
|
551
|
+
* @param obj - The object to display
|
|
552
|
+
* @param options - Optional formatting options (Node.js inspect options)
|
|
553
|
+
* @returns The logger instance for chaining
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* ```typescript
|
|
557
|
+
* const obj = { a: 1, b: { c: 2, d: { e: 3 } } }
|
|
558
|
+
* logger.dir(obj)
|
|
559
|
+
* logger.dir(obj, { depth: 1 }) // Limit nesting depth
|
|
560
|
+
* logger.dir(obj, { colors: true }) // Enable colors
|
|
561
|
+
* ```
|
|
374
562
|
*/
|
|
375
563
|
dir(obj, options) {
|
|
376
564
|
const con = privateConsole.get(this);
|
|
@@ -379,7 +567,18 @@ class Logger {
|
|
|
379
567
|
return this[incLogCallCountSymbol]();
|
|
380
568
|
}
|
|
381
569
|
/**
|
|
382
|
-
*
|
|
570
|
+
* Displays data as XML/HTML in a formatted way.
|
|
571
|
+
*
|
|
572
|
+
* Works like `console.dirxml()`. In Node.js, behaves the same as `dir()`.
|
|
573
|
+
*
|
|
574
|
+
* @param data - The data to display
|
|
575
|
+
* @returns The logger instance for chaining
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* logger.dirxml(document.body) // In browser environments
|
|
580
|
+
* logger.dirxml(xmlObject) // In Node.js
|
|
581
|
+
* ```
|
|
383
582
|
*/
|
|
384
583
|
dirxml(...data) {
|
|
385
584
|
const con = privateConsole.get(this);
|
|
@@ -388,25 +587,87 @@ class Logger {
|
|
|
388
587
|
return this[incLogCallCountSymbol]();
|
|
389
588
|
}
|
|
390
589
|
/**
|
|
391
|
-
*
|
|
590
|
+
* Logs an error message to stderr.
|
|
591
|
+
*
|
|
592
|
+
* Automatically applies current indentation. All arguments are formatted
|
|
593
|
+
* and logged like `console.error()`.
|
|
594
|
+
*
|
|
595
|
+
* @param args - Message and additional arguments to log
|
|
596
|
+
* @returns The logger instance for chaining
|
|
597
|
+
*
|
|
598
|
+
* @example
|
|
599
|
+
* ```typescript
|
|
600
|
+
* logger.error('Build failed')
|
|
601
|
+
* logger.error('Error code:', 500)
|
|
602
|
+
* logger.error('Details:', { message: 'Not found' })
|
|
603
|
+
* ```
|
|
392
604
|
*/
|
|
393
605
|
error(...args) {
|
|
394
606
|
return this.#apply("error", args);
|
|
395
607
|
}
|
|
396
608
|
/**
|
|
397
|
-
*
|
|
609
|
+
* Logs a newline to stderr only if the last line wasn't already blank.
|
|
610
|
+
*
|
|
611
|
+
* Prevents multiple consecutive blank lines. Useful for adding spacing
|
|
612
|
+
* between sections without creating excessive whitespace.
|
|
613
|
+
*
|
|
614
|
+
* @returns The logger instance for chaining
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* ```typescript
|
|
618
|
+
* logger.error('Error message')
|
|
619
|
+
* logger.errorNewline() // Adds blank line
|
|
620
|
+
* logger.errorNewline() // Does nothing (already blank)
|
|
621
|
+
* logger.error('Next section')
|
|
622
|
+
* ```
|
|
398
623
|
*/
|
|
399
624
|
errorNewline() {
|
|
400
625
|
return this.#lastWasBlank ? this : this.error("");
|
|
401
626
|
}
|
|
402
627
|
/**
|
|
403
|
-
*
|
|
628
|
+
* Logs a failure message with a red colored fail symbol.
|
|
629
|
+
*
|
|
630
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.fail` (red ✖).
|
|
631
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
632
|
+
* symbol, it will be stripped and replaced.
|
|
633
|
+
*
|
|
634
|
+
* @param args - Message and additional arguments to log
|
|
635
|
+
* @returns The logger instance for chaining
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* logger.fail('Build failed')
|
|
640
|
+
* logger.fail('Test suite failed:', { passed: 5, failed: 3 })
|
|
641
|
+
* ```
|
|
404
642
|
*/
|
|
405
643
|
fail(...args) {
|
|
406
644
|
return this.#symbolApply("fail", args);
|
|
407
645
|
}
|
|
408
646
|
/**
|
|
409
|
-
*
|
|
647
|
+
* Starts a new indented log group.
|
|
648
|
+
*
|
|
649
|
+
* If a label is provided, it's logged before increasing indentation.
|
|
650
|
+
* Groups can be nested. Each group increases indentation by the
|
|
651
|
+
* `kGroupIndentWidth` (default 2 spaces). Call `groupEnd()` to close.
|
|
652
|
+
*
|
|
653
|
+
* @param label - Optional label to display before the group
|
|
654
|
+
* @returns The logger instance for chaining
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
* ```typescript
|
|
658
|
+
* logger.group('Processing files:')
|
|
659
|
+
* logger.log('file1.js')
|
|
660
|
+
* logger.log('file2.js')
|
|
661
|
+
* logger.groupEnd()
|
|
662
|
+
*
|
|
663
|
+
* // Nested groups
|
|
664
|
+
* logger.group('Outer')
|
|
665
|
+
* logger.log('Outer content')
|
|
666
|
+
* logger.group('Inner')
|
|
667
|
+
* logger.log('Inner content')
|
|
668
|
+
* logger.groupEnd()
|
|
669
|
+
* logger.groupEnd()
|
|
670
|
+
* ```
|
|
410
671
|
*/
|
|
411
672
|
group(...label) {
|
|
412
673
|
const { length } = label;
|
|
@@ -422,7 +683,20 @@ class Logger {
|
|
|
422
683
|
return this;
|
|
423
684
|
}
|
|
424
685
|
/**
|
|
425
|
-
*
|
|
686
|
+
* Starts a new collapsed log group (alias for `group()`).
|
|
687
|
+
*
|
|
688
|
+
* In browser consoles, this creates a collapsed group. In Node.js,
|
|
689
|
+
* it behaves identically to `group()`.
|
|
690
|
+
*
|
|
691
|
+
* @param label - Optional label to display before the group
|
|
692
|
+
* @returns The logger instance for chaining
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* logger.groupCollapsed('Details')
|
|
697
|
+
* logger.log('Hidden by default in browsers')
|
|
698
|
+
* logger.groupEnd()
|
|
699
|
+
* ```
|
|
426
700
|
*/
|
|
427
701
|
// groupCollapsed is an alias of group.
|
|
428
702
|
// https://nodejs.org/api/console.html#consolegroupcollapsed
|
|
@@ -430,16 +704,54 @@ class Logger {
|
|
|
430
704
|
return ReflectApply(this.group, this, label);
|
|
431
705
|
}
|
|
432
706
|
/**
|
|
433
|
-
*
|
|
707
|
+
* Ends the current log group and decreases indentation.
|
|
708
|
+
*
|
|
709
|
+
* Must be called once for each `group()` or `groupCollapsed()` call
|
|
710
|
+
* to properly close the group and restore indentation.
|
|
711
|
+
*
|
|
712
|
+
* @returns The logger instance for chaining
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```typescript
|
|
716
|
+
* logger.group('Group 1')
|
|
717
|
+
* logger.log('Content')
|
|
718
|
+
* logger.groupEnd() // Closes 'Group 1'
|
|
719
|
+
* ```
|
|
434
720
|
*/
|
|
435
721
|
groupEnd() {
|
|
436
722
|
this.dedent(this[kGroupIndentationWidthSymbol]);
|
|
437
723
|
return this;
|
|
438
724
|
}
|
|
439
725
|
/**
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
726
|
+
* Increases the indentation level by adding spaces to the prefix.
|
|
727
|
+
*
|
|
728
|
+
* When called on the main logger, affects both stderr and stdout indentation.
|
|
729
|
+
* When called on a stream-bound logger (`.stderr` or `.stdout`), affects
|
|
730
|
+
* only that stream's indentation. Maximum indentation is 1000 spaces.
|
|
731
|
+
*
|
|
732
|
+
* @param spaces - Number of spaces to add to indentation
|
|
733
|
+
* @default 2
|
|
734
|
+
* @returns The logger instance for chaining
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ```typescript
|
|
738
|
+
* logger.log('Level 0')
|
|
739
|
+
* logger.indent()
|
|
740
|
+
* logger.log('Level 1')
|
|
741
|
+
* logger.indent()
|
|
742
|
+
* logger.log('Level 2')
|
|
743
|
+
* logger.dedent()
|
|
744
|
+
* logger.dedent()
|
|
745
|
+
*
|
|
746
|
+
* // Custom indent amount
|
|
747
|
+
* logger.indent(4)
|
|
748
|
+
* logger.log('Indented 4 spaces')
|
|
749
|
+
* logger.dedent(4)
|
|
750
|
+
*
|
|
751
|
+
* // Stream-specific indent
|
|
752
|
+
* logger.stdout.indent()
|
|
753
|
+
* logger.stdout.log('Only stdout is indented')
|
|
754
|
+
* ```
|
|
443
755
|
*/
|
|
444
756
|
indent(spaces = 2) {
|
|
445
757
|
const spacesToAdd = " ".repeat(Math.min(spaces, maxIndentation));
|
|
@@ -455,27 +767,86 @@ class Logger {
|
|
|
455
767
|
return this;
|
|
456
768
|
}
|
|
457
769
|
/**
|
|
458
|
-
*
|
|
770
|
+
* Logs an informational message with a blue colored info symbol.
|
|
771
|
+
*
|
|
772
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.info` (blue ℹ).
|
|
773
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
774
|
+
* symbol, it will be stripped and replaced.
|
|
775
|
+
*
|
|
776
|
+
* @param args - Message and additional arguments to log
|
|
777
|
+
* @returns The logger instance for chaining
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* ```typescript
|
|
781
|
+
* logger.info('Starting build process')
|
|
782
|
+
* logger.info('Configuration loaded:', config)
|
|
783
|
+
* logger.info('Using cache directory:', cacheDir)
|
|
784
|
+
* ```
|
|
459
785
|
*/
|
|
460
786
|
info(...args) {
|
|
461
787
|
return this.#symbolApply("info", args);
|
|
462
788
|
}
|
|
463
789
|
/**
|
|
464
|
-
*
|
|
790
|
+
* Logs a message to stdout.
|
|
791
|
+
*
|
|
792
|
+
* Automatically applies current indentation. All arguments are formatted
|
|
793
|
+
* and logged like `console.log()`. This is the primary method for
|
|
794
|
+
* standard output.
|
|
795
|
+
*
|
|
796
|
+
* @param args - Message and additional arguments to log
|
|
797
|
+
* @returns The logger instance for chaining
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* logger.log('Processing complete')
|
|
802
|
+
* logger.log('Items processed:', 42)
|
|
803
|
+
* logger.log('Results:', { success: true, count: 10 })
|
|
804
|
+
*
|
|
805
|
+
* // Method chaining
|
|
806
|
+
* logger.log('Step 1').log('Step 2').log('Step 3')
|
|
807
|
+
* ```
|
|
465
808
|
*/
|
|
466
809
|
log(...args) {
|
|
467
810
|
return this.#apply("log", args);
|
|
468
811
|
}
|
|
469
812
|
/**
|
|
470
|
-
*
|
|
813
|
+
* Logs a newline to stdout only if the last line wasn't already blank.
|
|
814
|
+
*
|
|
815
|
+
* Prevents multiple consecutive blank lines. Useful for adding spacing
|
|
816
|
+
* between sections without creating excessive whitespace.
|
|
817
|
+
*
|
|
818
|
+
* @returns The logger instance for chaining
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```typescript
|
|
822
|
+
* logger.log('Section 1')
|
|
823
|
+
* logger.logNewline() // Adds blank line
|
|
824
|
+
* logger.logNewline() // Does nothing (already blank)
|
|
825
|
+
* logger.log('Section 2')
|
|
826
|
+
* ```
|
|
471
827
|
*/
|
|
472
828
|
logNewline() {
|
|
473
829
|
return this.#lastWasBlank ? this : this.log("");
|
|
474
830
|
}
|
|
475
831
|
/**
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
832
|
+
* Resets all indentation to zero.
|
|
833
|
+
*
|
|
834
|
+
* When called on the main logger, resets both stderr and stdout indentation.
|
|
835
|
+
* When called on a stream-bound logger (`.stderr` or `.stdout`), resets
|
|
836
|
+
* only that stream's indentation.
|
|
837
|
+
*
|
|
838
|
+
* @returns The logger instance for chaining
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```typescript
|
|
842
|
+
* logger.indent().indent().indent()
|
|
843
|
+
* logger.log('Very indented')
|
|
844
|
+
* logger.resetIndent()
|
|
845
|
+
* logger.log('Back to zero indentation')
|
|
846
|
+
*
|
|
847
|
+
* // Reset only stdout
|
|
848
|
+
* logger.stdout.resetIndent()
|
|
849
|
+
* ```
|
|
479
850
|
*/
|
|
480
851
|
resetIndent() {
|
|
481
852
|
if (this.#boundStream) {
|
|
@@ -487,7 +858,30 @@ class Logger {
|
|
|
487
858
|
return this;
|
|
488
859
|
}
|
|
489
860
|
/**
|
|
490
|
-
*
|
|
861
|
+
* Logs a main step message with a blank line before it (stateless).
|
|
862
|
+
*
|
|
863
|
+
* Automatically adds a blank line before the message unless the last
|
|
864
|
+
* line was already blank. Useful for marking major steps in a process
|
|
865
|
+
* with clear visual separation.
|
|
866
|
+
*
|
|
867
|
+
* @param msg - The step message to log
|
|
868
|
+
* @param extras - Additional arguments to log
|
|
869
|
+
* @returns The logger instance for chaining
|
|
870
|
+
*
|
|
871
|
+
* @example
|
|
872
|
+
* ```typescript
|
|
873
|
+
* logger.step('Building project')
|
|
874
|
+
* logger.log('Compiling TypeScript...')
|
|
875
|
+
* logger.step('Running tests')
|
|
876
|
+
* logger.log('Running test suite...')
|
|
877
|
+
* // Output:
|
|
878
|
+
* // [blank line]
|
|
879
|
+
* // Building project
|
|
880
|
+
* // Compiling TypeScript...
|
|
881
|
+
* // [blank line]
|
|
882
|
+
* // Running tests
|
|
883
|
+
* // Running test suite...
|
|
884
|
+
* ```
|
|
491
885
|
*/
|
|
492
886
|
step(msg, ...extras) {
|
|
493
887
|
if (!this.#lastWasBlank) {
|
|
@@ -496,27 +890,104 @@ class Logger {
|
|
|
496
890
|
return this.log(msg, ...extras);
|
|
497
891
|
}
|
|
498
892
|
/**
|
|
499
|
-
*
|
|
893
|
+
* Logs an indented substep message (stateless).
|
|
894
|
+
*
|
|
895
|
+
* Adds a 2-space indent to the message without affecting the logger's
|
|
896
|
+
* indentation state. Useful for showing sub-items under a main step.
|
|
897
|
+
*
|
|
898
|
+
* @param msg - The substep message to log
|
|
899
|
+
* @param extras - Additional arguments to log
|
|
900
|
+
* @returns The logger instance for chaining
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* ```typescript
|
|
904
|
+
* logger.log('Installing dependencies:')
|
|
905
|
+
* logger.substep('Installing react')
|
|
906
|
+
* logger.substep('Installing typescript')
|
|
907
|
+
* logger.substep('Installing eslint')
|
|
908
|
+
* // Output:
|
|
909
|
+
* // Installing dependencies:
|
|
910
|
+
* // Installing react
|
|
911
|
+
* // Installing typescript
|
|
912
|
+
* // Installing eslint
|
|
913
|
+
* ```
|
|
500
914
|
*/
|
|
501
915
|
substep(msg, ...extras) {
|
|
502
916
|
const indentedMsg = ` ${msg}`;
|
|
503
917
|
return this.log(indentedMsg, ...extras);
|
|
504
918
|
}
|
|
505
919
|
/**
|
|
506
|
-
*
|
|
920
|
+
* Logs a success message with a green colored success symbol.
|
|
921
|
+
*
|
|
922
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.success` (green ✔).
|
|
923
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
924
|
+
* symbol, it will be stripped and replaced.
|
|
925
|
+
*
|
|
926
|
+
* @param args - Message and additional arguments to log
|
|
927
|
+
* @returns The logger instance for chaining
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```typescript
|
|
931
|
+
* logger.success('Build completed')
|
|
932
|
+
* logger.success('Tests passed:', { total: 42, passed: 42 })
|
|
933
|
+
* logger.success('Deployment successful')
|
|
934
|
+
* ```
|
|
507
935
|
*/
|
|
508
936
|
success(...args) {
|
|
509
937
|
return this.#symbolApply("success", args);
|
|
510
938
|
}
|
|
511
939
|
/**
|
|
512
|
-
*
|
|
513
|
-
*
|
|
940
|
+
* Logs a completion message with a success symbol (alias for `success()`).
|
|
941
|
+
*
|
|
942
|
+
* Provides semantic clarity when marking something as "done". Does NOT
|
|
943
|
+
* automatically clear the current line - call `clearLine()` first if
|
|
944
|
+
* needed after using `progress()`.
|
|
945
|
+
*
|
|
946
|
+
* @param args - Message and additional arguments to log
|
|
947
|
+
* @returns The logger instance for chaining
|
|
948
|
+
*
|
|
949
|
+
* @example
|
|
950
|
+
* ```typescript
|
|
951
|
+
* logger.done('Task completed')
|
|
952
|
+
*
|
|
953
|
+
* // After progress indicator
|
|
954
|
+
* logger.progress('Processing...')
|
|
955
|
+
* // ... do work ...
|
|
956
|
+
* logger.clearLine()
|
|
957
|
+
* logger.done('Processing complete')
|
|
958
|
+
* ```
|
|
514
959
|
*/
|
|
515
960
|
done(...args) {
|
|
516
961
|
return this.#symbolApply("success", args);
|
|
517
962
|
}
|
|
518
963
|
/**
|
|
519
|
-
*
|
|
964
|
+
* Displays data in a table format.
|
|
965
|
+
*
|
|
966
|
+
* Works like `console.table()`. Accepts arrays of objects or
|
|
967
|
+
* objects with nested objects. Optionally specify which properties
|
|
968
|
+
* to include in the table.
|
|
969
|
+
*
|
|
970
|
+
* @param tabularData - The data to display as a table
|
|
971
|
+
* @param properties - Optional array of property names to include
|
|
972
|
+
* @returns The logger instance for chaining
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
* ```typescript
|
|
976
|
+
* // Array of objects
|
|
977
|
+
* logger.table([
|
|
978
|
+
* { name: 'Alice', age: 30 },
|
|
979
|
+
* { name: 'Bob', age: 25 }
|
|
980
|
+
* ])
|
|
981
|
+
*
|
|
982
|
+
* // Specify properties to show
|
|
983
|
+
* logger.table(users, ['name', 'email'])
|
|
984
|
+
*
|
|
985
|
+
* // Object with nested objects
|
|
986
|
+
* logger.table({
|
|
987
|
+
* user1: { name: 'Alice', age: 30 },
|
|
988
|
+
* user2: { name: 'Bob', age: 25 }
|
|
989
|
+
* })
|
|
990
|
+
* ```
|
|
520
991
|
*/
|
|
521
992
|
table(tabularData, properties) {
|
|
522
993
|
const con = privateConsole.get(this);
|
|
@@ -525,7 +996,27 @@ class Logger {
|
|
|
525
996
|
return this[incLogCallCountSymbol]();
|
|
526
997
|
}
|
|
527
998
|
/**
|
|
528
|
-
*
|
|
999
|
+
* Ends a timer and logs the elapsed time.
|
|
1000
|
+
*
|
|
1001
|
+
* Logs the duration since `console.time()` was called with the same
|
|
1002
|
+
* label. The timer is stopped and removed.
|
|
1003
|
+
*
|
|
1004
|
+
* @param label - Optional label for the timer
|
|
1005
|
+
* @default 'default'
|
|
1006
|
+
* @returns The logger instance for chaining
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```typescript
|
|
1010
|
+
* console.time('operation')
|
|
1011
|
+
* // ... do work ...
|
|
1012
|
+
* logger.timeEnd('operation')
|
|
1013
|
+
* // Logs: "operation: 123.456ms"
|
|
1014
|
+
*
|
|
1015
|
+
* console.time()
|
|
1016
|
+
* // ... do work ...
|
|
1017
|
+
* logger.timeEnd()
|
|
1018
|
+
* // Logs: "default: 123.456ms"
|
|
1019
|
+
* ```
|
|
529
1020
|
*/
|
|
530
1021
|
timeEnd(label) {
|
|
531
1022
|
const con = privateConsole.get(this);
|
|
@@ -534,7 +1025,28 @@ class Logger {
|
|
|
534
1025
|
return this[incLogCallCountSymbol]();
|
|
535
1026
|
}
|
|
536
1027
|
/**
|
|
537
|
-
*
|
|
1028
|
+
* Logs the current value of a timer without stopping it.
|
|
1029
|
+
*
|
|
1030
|
+
* Logs the duration since `console.time()` was called with the same
|
|
1031
|
+
* label, but keeps the timer running. Can include additional data
|
|
1032
|
+
* to log alongside the time.
|
|
1033
|
+
*
|
|
1034
|
+
* @param label - Optional label for the timer
|
|
1035
|
+
* @param data - Additional data to log with the time
|
|
1036
|
+
* @default 'default'
|
|
1037
|
+
* @returns The logger instance for chaining
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* console.time('process')
|
|
1042
|
+
* // ... partial work ...
|
|
1043
|
+
* logger.timeLog('process', 'Checkpoint 1')
|
|
1044
|
+
* // Logs: "process: 123.456ms Checkpoint 1"
|
|
1045
|
+
* // ... more work ...
|
|
1046
|
+
* logger.timeLog('process', 'Checkpoint 2')
|
|
1047
|
+
* // Logs: "process: 234.567ms Checkpoint 2"
|
|
1048
|
+
* console.timeEnd('process')
|
|
1049
|
+
* ```
|
|
538
1050
|
*/
|
|
539
1051
|
timeLog(label, ...data) {
|
|
540
1052
|
const con = privateConsole.get(this);
|
|
@@ -543,7 +1055,24 @@ class Logger {
|
|
|
543
1055
|
return this[incLogCallCountSymbol]();
|
|
544
1056
|
}
|
|
545
1057
|
/**
|
|
546
|
-
*
|
|
1058
|
+
* Logs a stack trace to the console.
|
|
1059
|
+
*
|
|
1060
|
+
* Works like `console.trace()`. Shows the call stack leading to
|
|
1061
|
+
* where this method was called. Useful for debugging.
|
|
1062
|
+
*
|
|
1063
|
+
* @param message - Optional message to display with the trace
|
|
1064
|
+
* @param args - Additional arguments to log
|
|
1065
|
+
* @returns The logger instance for chaining
|
|
1066
|
+
*
|
|
1067
|
+
* @example
|
|
1068
|
+
* ```typescript
|
|
1069
|
+
* function debugFunction() {
|
|
1070
|
+
* logger.trace('Debug point reached')
|
|
1071
|
+
* }
|
|
1072
|
+
*
|
|
1073
|
+
* logger.trace('Trace from here')
|
|
1074
|
+
* logger.trace('Error context:', { userId: 123 })
|
|
1075
|
+
* ```
|
|
547
1076
|
*/
|
|
548
1077
|
trace(message, ...args) {
|
|
549
1078
|
const con = privateConsole.get(this);
|
|
@@ -552,13 +1081,45 @@ class Logger {
|
|
|
552
1081
|
return this[incLogCallCountSymbol]();
|
|
553
1082
|
}
|
|
554
1083
|
/**
|
|
555
|
-
*
|
|
1084
|
+
* Logs a warning message with a yellow colored warning symbol.
|
|
1085
|
+
*
|
|
1086
|
+
* Automatically prefixes the message with `LOG_SYMBOLS.warn` (yellow ⚠).
|
|
1087
|
+
* Always outputs to stderr. If the message starts with an existing
|
|
1088
|
+
* symbol, it will be stripped and replaced.
|
|
1089
|
+
*
|
|
1090
|
+
* @param args - Message and additional arguments to log
|
|
1091
|
+
* @returns The logger instance for chaining
|
|
1092
|
+
*
|
|
1093
|
+
* @example
|
|
1094
|
+
* ```typescript
|
|
1095
|
+
* logger.warn('Deprecated API used')
|
|
1096
|
+
* logger.warn('Low memory:', { available: '100MB' })
|
|
1097
|
+
* logger.warn('Missing optional configuration')
|
|
1098
|
+
* ```
|
|
556
1099
|
*/
|
|
557
1100
|
warn(...args) {
|
|
558
1101
|
return this.#symbolApply("warn", args);
|
|
559
1102
|
}
|
|
560
1103
|
/**
|
|
561
|
-
*
|
|
1104
|
+
* Writes text directly to stdout without a newline or indentation.
|
|
1105
|
+
*
|
|
1106
|
+
* Useful for progress indicators or custom formatting where you need
|
|
1107
|
+
* low-level control. Does not apply any indentation or formatting.
|
|
1108
|
+
*
|
|
1109
|
+
* @param text - The text to write
|
|
1110
|
+
* @returns The logger instance for chaining
|
|
1111
|
+
*
|
|
1112
|
+
* @example
|
|
1113
|
+
* ```typescript
|
|
1114
|
+
* logger.write('Processing... ')
|
|
1115
|
+
* // ... do work ...
|
|
1116
|
+
* logger.write('done\n')
|
|
1117
|
+
*
|
|
1118
|
+
* // Build a line incrementally
|
|
1119
|
+
* logger.write('Step 1')
|
|
1120
|
+
* logger.write('... Step 2')
|
|
1121
|
+
* logger.write('... Step 3\n')
|
|
1122
|
+
* ```
|
|
562
1123
|
*/
|
|
563
1124
|
write(text) {
|
|
564
1125
|
const con = privateConsole.get(this);
|
|
@@ -567,8 +1128,29 @@ class Logger {
|
|
|
567
1128
|
return this;
|
|
568
1129
|
}
|
|
569
1130
|
/**
|
|
570
|
-
*
|
|
571
|
-
*
|
|
1131
|
+
* Shows a progress indicator that can be cleared with `clearLine()`.
|
|
1132
|
+
*
|
|
1133
|
+
* Displays a simple status message with a '∴' prefix. Does not include
|
|
1134
|
+
* animation or spinner. Intended to be cleared once the operation completes.
|
|
1135
|
+
* The output stream (stderr or stdout) depends on whether the logger is
|
|
1136
|
+
* stream-bound.
|
|
1137
|
+
*
|
|
1138
|
+
* @param text - The progress message to display
|
|
1139
|
+
* @returns The logger instance for chaining
|
|
1140
|
+
*
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```typescript
|
|
1143
|
+
* logger.progress('Processing files...')
|
|
1144
|
+
* // ... do work ...
|
|
1145
|
+
* logger.clearLine()
|
|
1146
|
+
* logger.success('Files processed')
|
|
1147
|
+
*
|
|
1148
|
+
* // Stream-specific progress
|
|
1149
|
+
* logger.stdout.progress('Loading...')
|
|
1150
|
+
* // ... do work ...
|
|
1151
|
+
* logger.stdout.clearLine()
|
|
1152
|
+
* logger.stdout.log('Done')
|
|
1153
|
+
* ```
|
|
572
1154
|
*/
|
|
573
1155
|
progress(text) {
|
|
574
1156
|
const con = privateConsole.get(this);
|
|
@@ -579,7 +1161,32 @@ class Logger {
|
|
|
579
1161
|
return this;
|
|
580
1162
|
}
|
|
581
1163
|
/**
|
|
582
|
-
*
|
|
1164
|
+
* Clears the current line in the terminal.
|
|
1165
|
+
*
|
|
1166
|
+
* Moves the cursor to the beginning of the line and clears all content.
|
|
1167
|
+
* Works in both TTY and non-TTY environments. Useful for clearing
|
|
1168
|
+
* progress indicators created with `progress()`.
|
|
1169
|
+
*
|
|
1170
|
+
* The stream to clear (stderr or stdout) depends on whether the logger
|
|
1171
|
+
* is stream-bound.
|
|
1172
|
+
*
|
|
1173
|
+
* @returns The logger instance for chaining
|
|
1174
|
+
*
|
|
1175
|
+
* @example
|
|
1176
|
+
* ```typescript
|
|
1177
|
+
* logger.progress('Loading...')
|
|
1178
|
+
* // ... do work ...
|
|
1179
|
+
* logger.clearLine()
|
|
1180
|
+
* logger.success('Loaded')
|
|
1181
|
+
*
|
|
1182
|
+
* // Clear multiple progress updates
|
|
1183
|
+
* for (const file of files) {
|
|
1184
|
+
* logger.progress(`Processing ${file}`)
|
|
1185
|
+
* processFile(file)
|
|
1186
|
+
* logger.clearLine()
|
|
1187
|
+
* }
|
|
1188
|
+
* logger.success('All files processed')
|
|
1189
|
+
* ```
|
|
583
1190
|
*/
|
|
584
1191
|
clearLine() {
|
|
585
1192
|
const con = privateConsole.get(this);
|