@visulima/cerebro 3.0.0-alpha.2 → 3.0.0-alpha.21

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +334 -0
  2. package/LICENSE.md +589 -4096
  3. package/README.md +26 -0
  4. package/dist/commands/completion-command.d.ts +6 -5
  5. package/dist/commands/completion-command.js +2 -2
  6. package/dist/commands/help-command.d.ts +9 -9
  7. package/dist/commands/help-command.js +1 -1
  8. package/dist/commands/readme-command.d.ts +6 -5
  9. package/dist/commands/readme-command.js +20 -20
  10. package/dist/commands/version-command.d.ts +4 -3
  11. package/dist/index.d.ts +422 -95
  12. package/dist/index.js +1 -1
  13. package/dist/logger/create-pail-logger.d.ts +779 -8
  14. package/dist/logger/create-pail-logger.js +1 -1
  15. package/dist/packem_chunks/has-new-version.js +1 -1
  16. package/dist/packem_shared/Cerebro-DVWKQlmP.js +4 -0
  17. package/dist/packem_shared/VisulimaError-Bh91XNXu.js +76 -0
  18. package/dist/packem_shared/index-B0BiusY7.js +6 -0
  19. package/dist/packem_shared/index.d-Br8HpP0A.d.ts +93 -0
  20. package/dist/packem_shared/lazyNamed-DOmefeJM.js +1 -0
  21. package/dist/packem_shared/plugin-manager.d-Dz-wu1tI.d.ts +544 -0
  22. package/dist/packem_shared/renderError-B_XyYPKJ-B65kP-Ou.js +24 -0
  23. package/dist/packem_shared/{runtime-process-G-n-wOub.js → runtime-process-DKHFvYkv.js} +1 -1
  24. package/dist/plugins/error-handler-plugin.d.ts +21 -19
  25. package/dist/plugins/error-handler-plugin.js +1 -1
  26. package/dist/plugins/runtime-version-check-plugin.d.ts +22 -20
  27. package/dist/plugins/runtime-version-check-plugin.js +1 -1
  28. package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +21 -8
  29. package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -1
  30. package/dist/util/general/compile-cache.d.ts +41 -0
  31. package/dist/util/general/compile-cache.js +1 -0
  32. package/dist/util/general/heap-tuning.d.ts +18 -0
  33. package/dist/util/general/heap-tuning.js +1 -0
  34. package/package.json +52 -44
  35. package/dist/cli.d.ts +0 -203
  36. package/dist/constants.d.ts +0 -29
  37. package/dist/default-env.d.ts +0 -7
  38. package/dist/default-options.d.ts +0 -3
  39. package/dist/empty-toolbox.d.ts +0 -15
  40. package/dist/errors/cerebro-error.d.ts +0 -10
  41. package/dist/errors/command-not-found-error.d.ts +0 -9
  42. package/dist/errors/command-validation-error.d.ts +0 -10
  43. package/dist/errors/completion-error.d.ts +0 -9
  44. package/dist/errors/conflicting-options-error.d.ts +0 -10
  45. package/dist/errors/plugin-error.d.ts +0 -9
  46. package/dist/errors/update-notifier-error.d.ts +0 -7
  47. package/dist/packem_shared/Cerebro-aPZjbfzf.js +0 -4
  48. package/dist/packem_shared/VisulimaError-BJideSBf.js +0 -76
  49. package/dist/packem_shared/help-command-CIRIXN03.js +0 -1
  50. package/dist/packem_shared/index-DQ3pvLQH.js +0 -6
  51. package/dist/packem_shared/renderError-ZMlMvw1N-eVUSdl6c.js +0 -24
  52. package/dist/plugin-manager.d.ts +0 -53
  53. package/dist/plugins/update-notifier/cache.d.ts +0 -11
  54. package/dist/plugins/update-notifier/get-distribution-version.d.ts +0 -2
  55. package/dist/plugins/update-notifier/has-new-version.d.ts +0 -14
  56. package/dist/types/cli.d.ts +0 -102
  57. package/dist/types/command-line-usage.d.ts +0 -37
  58. package/dist/types/command.d.ts +0 -136
  59. package/dist/types/option-types.d.ts +0 -83
  60. package/dist/types/options.d.ts +0 -4
  61. package/dist/types/plugin.d.ts +0 -53
  62. package/dist/types/toolbox.d.ts +0 -96
  63. package/dist/util/arg-processing/get-boolean-values.d.ts +0 -7
  64. package/dist/util/arg-processing/get-parameter-option.d.ts +0 -7
  65. package/dist/util/arg-processing/map-option-type-label.d.ts +0 -3
  66. package/dist/util/arg-processing/option-is-boolean.d.ts +0 -9
  67. package/dist/util/arg-processing/remove-boolean-values.d.ts +0 -9
  68. package/dist/util/command-line-commands.d.ts +0 -10
  69. package/dist/util/command-line-usage/get-terminal-width.d.ts +0 -7
  70. package/dist/util/command-line-usage/index.d.ts +0 -3
  71. package/dist/util/command-line-usage/section/base-section.d.ts +0 -8
  72. package/dist/util/command-line-usage/section/content-section.d.ts +0 -65
  73. package/dist/util/command-line-usage/section/option-list-section.d.ts +0 -44
  74. package/dist/util/command-processing/command-processor.d.ts +0 -37
  75. package/dist/util/command-processing/command-validation.d.ts +0 -17
  76. package/dist/util/command-processing/nested-command-parser.d.ts +0 -25
  77. package/dist/util/command-processing/option-processor.d.ts +0 -44
  78. package/dist/util/data-processing/list-missing-arguments.d.ts +0 -15
  79. package/dist/util/data-processing/merge-arguments.d.ts +0 -7
  80. package/dist/util/general/find-alternatives.d.ts +0 -8
  81. package/dist/util/general/hide-bin.d.ts +0 -2
  82. package/dist/util/general/parse-raw-command.d.ts +0 -7
  83. package/dist/util/general/register-exception-handler.d.ts +0 -9
  84. package/dist/util/general/runtime-process.d.ts +0 -65
  85. package/dist/util/general/semver-gt.d.ts +0 -2
  86. package/dist/util/general/validate-input.d.ts +0 -24
  87. package/dist/util/process-env-variables.d.ts +0 -9
  88. package/dist/util/security.d.ts +0 -58
  89. package/dist/util/text-processing/template-format.d.ts +0 -5
@@ -1,8 +1,779 @@
1
- import type { ConstructorOptions, PailServerType } from "@visulima/pail";
2
- /**
3
- * Create a Pail logger.
4
- * @param options Optional configuration options for the logger
5
- * @returns A configured Pail logger instance
6
- */
7
- declare const createPailLogger: (options?: Partial<ConstructorOptions<string, string>>) => PailServerType<string, string>;
8
- export default createPailLogger;
1
+ import { InteractiveManager } from '@visulima/interactive-manager';
2
+ import { stringify } from 'safe-stable-stringify';
3
+ import { AnsiColors } from '@visulima/colorize';
4
+ /**
5
+ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
6
+
7
+ @category Type
8
+ */
9
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
10
+ /**
11
+ Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
12
+
13
+ Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
14
+
15
+ This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
16
+
17
+ @example
18
+ ```
19
+ import type {LiteralUnion} from 'type-fest';
20
+
21
+ // Before
22
+
23
+ type Pet = 'dog' | 'cat' | string;
24
+
25
+ const petWithoutAutocomplete: Pet = '';
26
+ // Start typing in your TypeScript-enabled IDE.
27
+ // You **will not** get auto-completion for `dog` and `cat` literals.
28
+
29
+ // After
30
+
31
+ type Pet2 = LiteralUnion<'dog' | 'cat', string>;
32
+
33
+ const petWithAutoComplete: Pet2 = '';
34
+ // You **will** get auto-completion for `dog` and `cat` literals.
35
+ ```
36
+
37
+ @category Type
38
+ */
39
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
40
+ /**
41
+ * Global namespace for extending Pail's metadata interface.
42
+ *
43
+ * This global declaration allows other packages and applications to extend
44
+ * the Meta interface with custom properties by declaring additional properties
45
+ * in the VisulimaPail.CustomMeta interface.
46
+ * @example
47
+ * ```typescript
48
+ * declare global {
49
+ * namespace VisulimaPail {
50
+ * interface CustomMeta<L> {
51
+ * userId?: string;
52
+ * requestId?: string;
53
+ * }
54
+ * }
55
+ * }
56
+ * ```
57
+ */
58
+ declare global {
59
+ namespace VisulimaPail {
60
+ interface CustomMeta<L> {}
61
+ }
62
+ }
63
+ /**
64
+ * Metadata object containing all information about a log entry.
65
+ *
66
+ * This interface defines the structure of metadata that is passed to reporters
67
+ * and processors. It contains all the contextual information about a log message
68
+ * including the message itself, timing information, error details, and more.
69
+ * @template L - The log level type
70
+ */
71
+ interface Meta<L> extends VisulimaPail.CustomMeta<L> {
72
+ badge: string | undefined;
73
+ context: any[] | undefined;
74
+ date: Date | string;
75
+ error: Error | undefined;
76
+ groups: string[];
77
+ label: string | undefined;
78
+ message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
79
+ prefix: string | undefined;
80
+ repeated?: number;
81
+ scope: string[] | undefined;
82
+ suffix: string | undefined;
83
+ traceError: Error | undefined;
84
+ type: {
85
+ level: ExtendedRfc5424LogLevels | L;
86
+ name: string;
87
+ };
88
+ }
89
+ /**
90
+ * Extended RFC 5424 Log Levels.
91
+ *
92
+ * Standard syslog severity levels as defined in RFC 5424, plus additional
93
+ * levels commonly used in modern applications. Each level has a numeric
94
+ * priority where lower numbers indicate higher severity.
95
+ * @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
96
+ */
97
+ type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
98
+ /**
99
+ * Default Log Types.
100
+ *
101
+ * Predefined semantic log types that provide meaningful categorization
102
+ * for different kinds of log messages. Each type has associated styling
103
+ * and log level configuration.
104
+ */
105
+ type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "warning" | "watch";
106
+ /**
107
+ * Logger Function Type.
108
+ *
109
+ * Represents a logging function that can accept either a structured Message object
110
+ * or multiple arguments in the traditional console.log style.
111
+ */
112
+ interface LoggerFunction {
113
+ (message: Message): void;
114
+ (...message: any[]): void;
115
+ }
116
+ /**
117
+ * Logger Configuration.
118
+ *
119
+ * Configuration object that defines how a specific logger type should behave,
120
+ * including its visual appearance and log level.
121
+ * @template L - The log level type
122
+ */
123
+ interface LoggerConfiguration<L extends string> {
124
+ badge?: string;
125
+ color?: AnsiColors;
126
+ label: string;
127
+ logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
128
+ }
129
+ /**
130
+ * Logger Types Configuration.
131
+ *
132
+ * A record mapping logger type names to their configurations.
133
+ * @template T - Custom logger type names
134
+ * @template L - Log level types
135
+ */
136
+ type LoggerTypesConfig<T extends string, L extends string> = Record<T, Partial<LoggerConfiguration<L>>>;
137
+ /**
138
+ * Default Logger Types Configuration.
139
+ *
140
+ * A complete mapping of all default log types to their full configurations.
141
+ * @template L - Log level types
142
+ */
143
+
144
+ /**
145
+ * Read-only Metadata.
146
+ *
147
+ * Immutable version of the Meta interface for use in reporters.
148
+ * @template L - The log level type
149
+ */
150
+ type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
151
+ /**
152
+ * Reporter Interface.
153
+ *
154
+ * Base interface for all reporters. Reporters are responsible for
155
+ * outputting log messages to various destinations (console, files, etc.).
156
+ * @template L - The log level type
157
+ */
158
+ interface Reporter<L extends string> {
159
+ log: (meta: ReadonlyMeta<L>) => void;
160
+ }
161
+ /**
162
+ * Stream-Aware Reporter Interface.
163
+ *
164
+ * Extends Reporter with the ability to work with Node.js streams.
165
+ * Used for server-side reporters that need to write to stdout/stderr.
166
+ * @template L - The log level type
167
+ */
168
+
169
+ /**
170
+ * Processor Interface.
171
+ *
172
+ * Base interface for all processors. Processors can modify or enhance
173
+ * log metadata before it reaches reporters.
174
+ * @template L - The log level type
175
+ */
176
+ interface Processor<L extends string> {
177
+ /** Process the log metadata */
178
+ process: (meta: Meta<L>) => Meta<L>;
179
+ }
180
+ interface ConstructorOptions<T extends string, L extends string> {
181
+ disabled?: boolean;
182
+ logLevel?: LiteralUnion<ExtendedRfc5424LogLevels, L>;
183
+ logLevels?: Partial<Record<ExtendedRfc5424LogLevels, number>> & Record<L, number>;
184
+ messages?: {
185
+ timerEnd?: string;
186
+ timerStart?: string;
187
+ };
188
+ processors?: Processor<L>[];
189
+ rawReporter?: Reporter<L>;
190
+ reporters?: Reporter<L>[];
191
+ scope?: string[] | string;
192
+ throttle?: number;
193
+ throttleMin?: number;
194
+ types?: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>;
195
+ }
196
+ interface ServerConstructorOptions<T extends string, L extends string> extends ConstructorOptions<T, L> {
197
+ interactive?: boolean;
198
+ stderr: NodeJS.WriteStream;
199
+ stdout: NodeJS.WriteStream;
200
+ }
201
+ type Message = {
202
+ context?: any[];
203
+ message: any;
204
+ prefix?: string;
205
+ suffix?: string;
206
+ };
207
+ /**
208
+ * Pail Browser Implementation.
209
+ *
210
+ * A comprehensive logging library for browser environments with support for
211
+ * multiple log levels, custom types, processors, reporters, and advanced features
212
+ * like throttling, scoping, timers, and counters.
213
+ * @template T - Custom logger types (string union)
214
+ * @template L - Log level types (string union)
215
+ * @example
216
+ * ```typescript
217
+ * const logger = new PailBrowserImpl({
218
+ * logLevel: "debug",
219
+ * types: {
220
+ * http: { color: "blue", label: "HTTP", logLevel: "info" }
221
+ * },
222
+ * reporters: [new JsonReporter()]
223
+ * });
224
+ *
225
+ * logger.info("Application started");
226
+ * logger.http("GET /api/users 200");
227
+ * logger.error("Something went wrong", error);
228
+ * ```
229
+ */
230
+ declare class PailBrowserImpl<T extends string = string, L extends string = string> {
231
+ #private;
232
+ protected timersMap: Map<string, number>;
233
+ protected countMap: Map<string, number>;
234
+ protected seqTimers: Set<string>;
235
+ protected readonly lastLog: {
236
+ count?: number;
237
+ object?: Meta<L>;
238
+ time?: Date;
239
+ timeout?: ReturnType<typeof setTimeout>;
240
+ };
241
+ protected readonly logLevels: Record<string, number>;
242
+ protected disabled: boolean;
243
+ protected paused: boolean;
244
+ protected messageQueue: {
245
+ messageObject: any[];
246
+ raw: boolean;
247
+ type: LiteralUnion<DefaultLogTypes, T>;
248
+ }[];
249
+ protected scopeName: string[];
250
+ protected readonly types: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>;
251
+ protected readonly longestLabel: string;
252
+ protected readonly processors: Set<Processor<L>>;
253
+ protected readonly generalLogLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
254
+ protected reporters: Set<Reporter<L>>;
255
+ protected readonly throttle: number;
256
+ protected readonly throttleMin: number;
257
+ protected readonly stringify: typeof stringify;
258
+ protected groups: string[];
259
+ protected readonly startTimerMessage: string;
260
+ protected readonly endTimerMessage: string;
261
+ protected rawReporter: Reporter<L>;
262
+ protected force: Record<string, LoggerFunction>;
263
+ /**
264
+ * Creates a new Pail browser logger instance.
265
+ *
266
+ * Initializes the logger with the provided configuration options,
267
+ * setting up reporters, processors, log levels, and other internal state.
268
+ * @param options Configuration options for the logger
269
+ */
270
+ constructor(options: ConstructorOptions<T, L>);
271
+ /**
272
+ * Wraps the global console methods to redirect them through the logger.
273
+ *
274
+ * This method replaces console methods (log, info, warn, error, etc.) with
275
+ * calls to the corresponding logger methods. The original console methods
276
+ * are backed up and can be restored using restoreConsole().
277
+ * @example
278
+ * ```typescript
279
+ * const logger = createPail();
280
+ * logger.wrapConsole();
281
+ *
282
+ * console.log("This will go through the logger");
283
+ * console.error("This too!");
284
+ *
285
+ * logger.restoreConsole(); // Restore original console methods
286
+ * ```
287
+ */
288
+ wrapConsole(): void;
289
+ /**
290
+ * Restores the original global console methods.
291
+ *
292
+ * This method restores the console methods that were backed up by wrapConsole().
293
+ * After calling this, console methods will work as they did before wrapping.
294
+ * @example
295
+ * ```typescript
296
+ * const logger = createPail();
297
+ * logger.wrapConsole();
298
+ *
299
+ * // Console methods are now wrapped
300
+ * logger.restoreConsole();
301
+ * // Console methods are restored to original behavior
302
+ * ```
303
+ */
304
+ restoreConsole(): void;
305
+ /**
306
+ * Wraps uncaught exception and unhandled rejection handlers.
307
+ *
308
+ * This method sets up global error handlers that will log uncaught exceptions
309
+ * and unhandled promise rejections through the logger. This is useful for
310
+ * capturing and logging application crashes.
311
+ * @example
312
+ * ```typescript
313
+ * const logger = createPail();
314
+ * logger.wrapException();
315
+ *
316
+ * // Now uncaught errors will be logged
317
+ * throw new Error("This will be logged");
318
+ * ```
319
+ */
320
+ wrapException(): void;
321
+ /**
322
+ * Disables all logging output.
323
+ *
324
+ * When disabled, all log calls will be silently ignored and no output
325
+ * will be produced by any reporters. This can be useful for temporarily
326
+ * suppressing log output in production or during testing.
327
+ * @example
328
+ * ```typescript
329
+ * const logger = createPail();
330
+ * logger.disable();
331
+ * logger.info("This won't be logged"); // Silent
332
+ * logger.enable();
333
+ * logger.info("This will be logged"); // Output produced
334
+ * ```
335
+ */
336
+ disable(): void;
337
+ /**
338
+ * Enables logging output.
339
+ *
340
+ * Re-enables logging after it has been disabled. All subsequent log calls
341
+ * will produce output according to the configured reporters.
342
+ * @example
343
+ * ```typescript
344
+ * const logger = createPail();
345
+ * logger.disable();
346
+ * logger.info("This won't be logged");
347
+ * logger.enable(); // Re-enable logging
348
+ * logger.info("This will be logged");
349
+ * ```
350
+ */
351
+ enable(): void;
352
+ /**
353
+ * Checks if logging is currently enabled.
354
+ *
355
+ * Returns true if logging is enabled and false if it has been disabled.
356
+ * @returns True if logging is enabled, false if disabled
357
+ * @example
358
+ * ```typescript
359
+ * const logger = createPail();
360
+ * console.log(logger.isEnabled()); // true
361
+ * logger.disable();
362
+ * console.log(logger.isEnabled()); // false
363
+ * ```
364
+ */
365
+ isEnabled(): boolean;
366
+ /**
367
+ * Pauses logging and starts queuing messages.
368
+ *
369
+ * When paused, all log calls will be queued instead of being output immediately.
370
+ * The queued messages will be processed when resume() is called. This is useful
371
+ * for temporarily buffering log output during critical operations.
372
+ * @example
373
+ * ```typescript
374
+ * const logger = createPail();
375
+ * logger.pause();
376
+ * logger.info("This will be queued"); // Queued, not output yet
377
+ * logger.warn("This too"); // Also queued
378
+ * logger.resume(); // Now both messages are output
379
+ * ```
380
+ */
381
+ pause(): void;
382
+ /**
383
+ * Resumes logging and flushes all queued messages.
384
+ *
385
+ * Processes all messages that were queued during the pause period and
386
+ * resumes normal logging behavior. Messages are output in the order
387
+ * they were originally called.
388
+ * @example
389
+ * ```typescript
390
+ * const logger = createPail();
391
+ * logger.pause();
392
+ * logger.info("Message 1"); // Queued
393
+ * logger.info("Message 2"); // Queued
394
+ * logger.resume(); // Both messages are now output in order
395
+ * logger.info("Message 3"); // Output immediately
396
+ * ```
397
+ */
398
+ resume(): void;
399
+ /**
400
+ * Creates a scoped logger instance.
401
+ *
402
+ * Returns a new logger instance that inherits all configuration but adds
403
+ * the specified scope names to all log messages. This is useful for
404
+ * categorizing logs by component, module, or feature.
405
+ * @template N - The new custom logger type names
406
+ * @param name Scope names to apply to all log messages
407
+ * @returns A new scoped logger instance
408
+ * @throws {Error} If no scope name is provided
409
+ * @example
410
+ * ```typescript
411
+ * const logger = createPail();
412
+ * const scopedLogger = logger.scope("auth", "login");
413
+ * scopedLogger.info("User logged in"); // Will include scope: ["auth", "login"]
414
+ * ```
415
+ */
416
+ scope<N extends string = T>(...name: string[]): PailBrowserType<N, L>;
417
+ /**
418
+ * Removes the current scope from the logger.
419
+ *
420
+ * Clears all scope names that were set by previous scope() calls.
421
+ * After calling this, log messages will no longer include scope information.
422
+ * @example
423
+ * ```typescript
424
+ * const logger = createPail();
425
+ * const scopedLogger = logger.scope("auth");
426
+ * scopedLogger.info("Scoped message"); // Has scope
427
+ * scopedLogger.unscope();
428
+ * scopedLogger.info("Unscoped message"); // No scope
429
+ * ```
430
+ */
431
+ unscope(): void;
432
+ /**
433
+ * Creates a child logger that inherits settings from the parent.
434
+ *
435
+ * Returns a new logger instance that inherits all configuration from the parent
436
+ * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
437
+ * you to override only what you need. Child loggers are independent instances with
438
+ * their own state (timers, counters, etc.).
439
+ * @template N - The new custom logger type names
440
+ * @template LC - The new log level types
441
+ * @param options Configuration options to override or extend parent settings
442
+ * @returns A new child logger instance
443
+ * @example
444
+ * ```typescript
445
+ * const parent = createPail({
446
+ * logLevel: "info",
447
+ * types: { http: { label: "HTTP", logLevel: "info" } },
448
+ * reporters: [new PrettyReporter()],
449
+ * });
450
+ *
451
+ * // Child inherits parent settings but overrides log level
452
+ * const child = parent.child({ logLevel: "debug" });
453
+ * child.info("This will be logged"); // Uses debug level from child
454
+ * child.http("GET /api 200"); // Inherits http type from parent
455
+ *
456
+ * // Child can add new types
457
+ * const childWithNewType = parent.child({
458
+ * types: { db: { label: "DB", logLevel: "info" } },
459
+ * });
460
+ * childWithNewType.db("Query executed"); // New type available
461
+ * ```
462
+ */
463
+ child<N extends string = T, LC extends string = L>(options?: Partial<ConstructorOptions<N, LC>>): PailBrowserType<N, LC>;
464
+ /**
465
+ * Starts a timer with the specified label.
466
+ *
467
+ * Records the current timestamp and associates it with the given label.
468
+ * Multiple timers can be active simultaneously with different labels.
469
+ * @param label The timer label (defaults to "default")
470
+ * @example
471
+ * ```typescript
472
+ * const logger = createPail();
473
+ * logger.time("operation");
474
+ * // ... some operation ...
475
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
476
+ * ```
477
+ */
478
+ time(label?: string): void;
479
+ /**
480
+ * Logs the current elapsed time for a timer without stopping it.
481
+ *
482
+ * Calculates and logs the time elapsed since the timer was started,
483
+ * but keeps the timer running. If no label is provided, uses the
484
+ * most recently started timer.
485
+ * @param label The timer label (uses last timer if not specified)
486
+ * @param data Additional data to include in the log message
487
+ * @example
488
+ * ```typescript
489
+ * const logger = createPail();
490
+ * logger.time("task");
491
+ * // ... some work ...
492
+ * logger.timeLog("task"); // Logs current elapsed time
493
+ * // ... more work ...
494
+ * logger.timeEnd("task"); // Logs final time and stops timer
495
+ * ```
496
+ */
497
+ timeLog(label?: string, ...data: unknown[]): void;
498
+ /**
499
+ * Stops a timer and logs the final elapsed time.
500
+ *
501
+ * Calculates the total time elapsed since the timer was started,
502
+ * logs the result, and removes the timer. If no label is provided,
503
+ * uses the most recently started timer.
504
+ * @param label The timer label (uses last timer if not specified)
505
+ * @example
506
+ * ```typescript
507
+ * const logger = createPail();
508
+ * logger.time("operation");
509
+ * // ... perform operation ...
510
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
511
+ * ```
512
+ */
513
+ timeEnd(label?: string): void;
514
+ /**
515
+ * Starts a log group with the specified label.
516
+ *
517
+ * Groups related log messages together. In browser environments,
518
+ * this uses the native console.group() functionality. In other
519
+ * environments, it tracks group nesting internally.
520
+ * @param label The group label (defaults to "console.group")
521
+ * @example
522
+ * ```typescript
523
+ * const logger = createPail();
524
+ * logger.group("Database Operations");
525
+ * logger.info("Connecting to database");
526
+ * logger.info("Running migration");
527
+ * logger.groupEnd(); // End the group
528
+ * ```
529
+ */
530
+ group(label?: string): void;
531
+ /**
532
+ * Ends the current log group.
533
+ *
534
+ * Closes the most recently opened log group. In browser environments,
535
+ * this uses the native console.groupEnd() functionality.
536
+ * @example
537
+ * ```typescript
538
+ * const logger = createPail();
539
+ * logger.group("Processing");
540
+ * logger.info("Step 1");
541
+ * logger.info("Step 2");
542
+ * logger.groupEnd(); // Closes the "Processing" group
543
+ * ```
544
+ */
545
+ groupEnd(): void;
546
+ /**
547
+ * Increments and logs a counter with the specified label.
548
+ *
549
+ * Maintains an internal counter for each label and logs the current count
550
+ * each time it's called. Useful for tracking how many times certain
551
+ * code paths are executed.
552
+ * @param label The counter label (defaults to "default")
553
+ * @example
554
+ * ```typescript
555
+ * const logger = createPail();
556
+ * logger.count("requests"); // Logs: "requests: 1"
557
+ * logger.count("requests"); // Logs: "requests: 2"
558
+ * logger.count("errors"); // Logs: "errors: 1"
559
+ * ```
560
+ */
561
+ count(label?: string): void;
562
+ /**
563
+ * Resets a counter to zero.
564
+ *
565
+ * Removes the counter with the specified label, effectively resetting
566
+ * it to zero. If the counter doesn't exist, logs a warning.
567
+ * @param label The counter label to reset (defaults to "default")
568
+ * @example
569
+ * ```typescript
570
+ * const logger = createPail();
571
+ * logger.count("requests"); // Logs: "requests: 1"
572
+ * logger.countReset("requests"); // Resets counter
573
+ * logger.count("requests"); // Logs: "requests: 1" (starts over)
574
+ * ```
575
+ */
576
+ countReset(label?: string): void;
577
+ /**
578
+ * Clears the console output.
579
+ *
580
+ * Calls the native console.clear() method to clear all output from
581
+ * the console. This is a convenience method that wraps the native
582
+ * console.clear() functionality.
583
+ * @example
584
+ * ```typescript
585
+ * const logger = createPail();
586
+ * logger.info("Some message");
587
+ * logger.clear(); // Clears the console
588
+ * ```
589
+ */
590
+ clear(): void;
591
+ /**
592
+ * Logs a raw message bypassing normal processing.
593
+ *
594
+ * Sends a message directly to the raw reporter without going through
595
+ * the normal logging pipeline (processors, throttling, etc.). This is
596
+ * useful for logging that needs to bypass all formatting and processing.
597
+ * @param message The raw message to log
598
+ * @param arguments_ Additional arguments to include
599
+ * @example
600
+ * ```typescript
601
+ * const logger = createPail();
602
+ * logger.raw("Direct message", { data: "value" });
603
+ * ```
604
+ */
605
+ raw(message: string, ...arguments_: unknown[]): void;
606
+ protected extendReporter(reporter: Reporter<L>): Reporter<L>;
607
+ protected registerReporters(reporters: Reporter<L>[]): void;
608
+ protected registerProcessors(processors: Processor<L>[]): void;
609
+ protected logger(type: LiteralUnion<DefaultLogTypes, T>, raw: boolean, force: boolean, ...messageObject: unknown[]): void;
610
+ }
611
+ type PailBrowserType<T extends string = string, L extends string = string> = Console & (new <TC extends string = string, LC extends string = string>(options?: ConstructorOptions<TC, LC>) => PailBrowserType<TC, LC>) & PailBrowserImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction> & {
612
+ force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
613
+ };
614
+ declare class PailServerImpl<T extends string = string, L extends string = string> extends PailBrowserImpl<T, L> {
615
+ #private;
616
+ readonly options: ServerConstructorOptions<T, L>;
617
+ protected readonly stdout: NodeJS.WriteStream;
618
+ protected readonly stderr: NodeJS.WriteStream;
619
+ protected interactiveManager: InteractiveManager | undefined;
620
+ protected readonly interactive: boolean;
621
+ /**
622
+ * Creates a new Pail server logger instance.
623
+ *
624
+ * Initializes the server-compatible logger with streams, interactive support,
625
+ * and server-specific configuration options.
626
+ * @param options Server-specific configuration options
627
+ */
628
+ constructor(options: ServerConstructorOptions<T, L>);
629
+ override scope<N extends string = T>(...name: string[]): PailServerType<N, L>;
630
+ /**
631
+ * Creates a child logger that inherits settings from the parent.
632
+ *
633
+ * Returns a new logger instance that inherits all configuration from the parent
634
+ * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
635
+ * you to override only what you need. Child loggers are independent instances with
636
+ * their own state (timers, counters, etc.).
637
+ * @template N - The new custom logger type names
638
+ * @template LC - The new log level types
639
+ * @param options Configuration options to override or extend parent settings
640
+ * @returns A new child logger instance
641
+ * @example
642
+ * ```typescript
643
+ * const parent = createPail({
644
+ * logLevel: "info",
645
+ * types: { http: { label: "HTTP", logLevel: "info" } },
646
+ * reporters: [new PrettyReporter()],
647
+ * });
648
+ *
649
+ * // Child inherits parent settings but overrides log level
650
+ * const child = parent.child({ logLevel: "debug" });
651
+ * child.info("This will be logged"); // Uses debug level from child
652
+ * child.http("GET /api 200"); // Inherits http type from parent
653
+ *
654
+ * // Child can add new types
655
+ * const childWithNewType = parent.child({
656
+ * types: { db: { label: "DB", logLevel: "info" } },
657
+ * });
658
+ * childWithNewType.db("Query executed"); // New type available
659
+ * ```
660
+ */
661
+ override child<N extends string = T, LC extends string = L>(options?: Partial<ConstructorOptions<N, LC>> & Partial<Pick<ServerConstructorOptions<N, LC>, "interactive" | "stderr" | "stdout">>): PailServerType<N, LC>;
662
+ /**
663
+ * Gets the interactive manager instance if interactive mode is enabled.
664
+ *
665
+ * Returns the InteractiveManager instance that handles interactive terminal
666
+ * features like progress bars and dynamic updates. Only available when
667
+ * interactive mode is enabled in the constructor options.
668
+ * @returns The interactive manager instance, or undefined if not in interactive mode
669
+ * @example
670
+ * ```typescript
671
+ * const logger = createPail({ interactive: true });
672
+ * const manager = logger.getInteractiveManager();
673
+ * if (manager) {
674
+ * manager.hook();
675
+ * // Use interactive features
676
+ * manager.unhook();
677
+ * }
678
+ * ```
679
+ */
680
+ getInteractiveManager(): InteractiveManager | undefined;
681
+ /**
682
+ * Wraps stdout and stderr streams to redirect them through the logger.
683
+ *
684
+ * Intercepts writes to process.stdout and process.stderr, redirecting them
685
+ * through the logger instead of writing directly to the streams. This allows
686
+ * all output to be processed by the logging pipeline.
687
+ * @example
688
+ * ```typescript
689
+ * const logger = createPail();
690
+ * logger.wrapStd();
691
+ *
692
+ * console.log("This goes through logger");
693
+ * process.stdout.write("This too");
694
+ *
695
+ * logger.restoreStd(); // Restore original streams
696
+ * ```
697
+ */
698
+ wrapStd(): void;
699
+ /**
700
+ * Restores the original stdout and stderr streams.
701
+ *
702
+ * Removes the stream wrapping that was applied by wrapStd(),
703
+ * restoring the original stream write methods.
704
+ * @example
705
+ * ```typescript
706
+ * const logger = createPail();
707
+ * logger.wrapStd();
708
+ * // Streams are wrapped
709
+ * logger.restoreStd();
710
+ * // Streams are restored to original behavior
711
+ * ```
712
+ */
713
+ restoreStd(): void;
714
+ /**
715
+ * Wraps all output sources (console and streams).
716
+ *
717
+ * Convenience method that calls both wrapConsole() and wrapStd()
718
+ * to redirect all output through the logger.
719
+ * @example
720
+ * ```typescript
721
+ * const logger = createPail();
722
+ * logger.wrapAll(); // Wraps console and streams
723
+ *
724
+ * // All output now goes through logger
725
+ * console.log("Console output");
726
+ * process.stdout.write("Stream output");
727
+ *
728
+ * logger.restoreAll(); // Restore everything
729
+ * ```
730
+ */
731
+ wrapAll(): void;
732
+ /**
733
+ * Restores all wrapped output sources.
734
+ *
735
+ * Convenience method that calls both restoreConsole() and restoreStd()
736
+ * to restore all original output behavior.
737
+ * @example
738
+ * ```typescript
739
+ * const logger = createPail();
740
+ * logger.wrapAll();
741
+ * // All output is wrapped
742
+ * logger.restoreAll();
743
+ * // All output sources are restored
744
+ * ```
745
+ */
746
+ restoreAll(): void;
747
+ /**
748
+ * Clears the terminal screen.
749
+ *
750
+ * Sends ANSI escape sequences to clear the terminal screen and move
751
+ * the cursor to the top-left position. This overrides the browser
752
+ * implementation to work with terminal streams.
753
+ * @example
754
+ * ```typescript
755
+ * const logger = createPail();
756
+ * logger.info("Some output");
757
+ * logger.clear(); // Clears the terminal screen
758
+ * ```
759
+ */
760
+ override clear(): void;
761
+ protected override extendReporter(reporter: Reporter<L>): Reporter<L>;
762
+ }
763
+ type PailServerType<T extends string = string, L extends string = string> = Console & (new <TC extends string = string, LC extends string = string>(options?: ServerConstructorOptions<TC, LC>) => PailServerType<TC, LC>) & PailServerImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction> & {
764
+ force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
765
+ };
766
+ /**
767
+ * Options for creating a PailError.
768
+ *
769
+ * Extends standard error properties with self-documenting fields
770
+ * that provide actionable context for debugging, particularly useful
771
+ * for AI-assisted log analysis.
772
+ */
773
+ /**
774
+ * Create a Pail logger.
775
+ * @param options Optional configuration options for the logger
776
+ * @returns A configured Pail logger instance
777
+ */
778
+ declare const createPailLogger: (options?: Partial<ConstructorOptions<string, string>>) => PailServerType;
779
+ export { createPailLogger as default };