@visulima/cerebro 3.0.0-alpha.3 → 3.0.0-alpha.31

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