@visulima/pail 4.0.0-alpha.10 → 4.0.0-alpha.12

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 (106) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE.md +143 -931
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +2 -2
  6. package/dist/index.server.d.ts +722 -65
  7. package/dist/index.server.js +27 -410
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/elysia.js +2 -2
  10. package/dist/middleware/express.d.ts +73 -71
  11. package/dist/middleware/express.js +1 -1
  12. package/dist/middleware/fastify.d.ts +69 -67
  13. package/dist/middleware/fastify.js +2 -2
  14. package/dist/middleware/hono.d.ts +74 -72
  15. package/dist/middleware/next/handler.d.ts +101 -34
  16. package/dist/middleware/sveltekit.d.ts +100 -98
  17. package/dist/object-tree.d.ts +67 -70
  18. package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
  19. package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
  20. package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
  21. package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
  22. package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-CIbrmjUV.js} +2 -4
  23. package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-CNJEO9g7.js} +1250 -15
  24. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  25. package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CkqCt5hg.js} +2300 -2298
  26. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  27. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  28. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  29. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  30. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  31. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  32. package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
  33. package/dist/processor/caller/caller-processor.d.ts +49 -47
  34. package/dist/processor/caller/caller-processor.js +1 -1
  35. package/dist/processor/environment-processor.d.ts +113 -113
  36. package/dist/processor/message-formatter-processor.d.ts +51 -49
  37. package/dist/processor/message-formatter-processor.js +2 -2
  38. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  39. package/dist/processor/redact-processor.d.ts +60 -41
  40. package/dist/processor/sampling-processor.d.ts +102 -101
  41. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  42. package/dist/reporter/file/json-file-reporter.js +1 -1
  43. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  44. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  45. package/dist/reporter/http/http-reporter.d.ts +40 -36
  46. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  47. package/dist/reporter/http/http-reporter.edge-light.js +1 -5
  48. package/dist/reporter/json/index.browser.d.ts +99 -3
  49. package/dist/reporter/json/index.browser.js +2 -2
  50. package/dist/reporter/json/index.d.ts +51 -3
  51. package/dist/reporter/json/index.js +2 -2
  52. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +219 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  57. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  58. package/dist/wide-event.d.ts +5 -300
  59. package/dist/wide-event.js +3 -2
  60. package/package.json +9 -21
  61. package/dist/constants.d.ts +0 -37
  62. package/dist/interactive/index.d.ts +0 -2
  63. package/dist/interactive/index.js +0 -2
  64. package/dist/interactive/interactive-manager.d.ts +0 -108
  65. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  66. package/dist/middleware/next/middleware.d.ts +0 -59
  67. package/dist/middleware/next/storage.d.ts +0 -14
  68. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  69. package/dist/middleware/shared/headers.d.ts +0 -14
  70. package/dist/middleware/shared/routes.d.ts +0 -30
  71. package/dist/middleware/shared/storage.d.ts +0 -29
  72. package/dist/packem_shared/InteractiveManager-CowYA3Hx.js +0 -178
  73. package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
  74. package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
  75. package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
  76. package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
  77. package/dist/pail.browser.d.ts +0 -412
  78. package/dist/pail.server.d.ts +0 -233
  79. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  80. package/dist/progress-bar.d.ts +0 -145
  81. package/dist/progress-bar.js +0 -459
  82. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  83. package/dist/reporter/http/utils/compression.d.ts +0 -7
  84. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  85. package/dist/reporter/http/utils/retry.d.ts +0 -27
  86. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  87. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  88. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  89. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  90. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  91. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  92. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  93. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  94. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  95. package/dist/reporter/utils/format-label.d.ts +0 -3
  96. package/dist/spinner.d.ts +0 -220
  97. package/dist/spinner.js +0 -2183
  98. package/dist/types.d.ts +0 -241
  99. package/dist/utils/ansi-escapes.d.ts +0 -4
  100. package/dist/utils/arrayify.d.ts +0 -2
  101. package/dist/utils/get-longest-badge.d.ts +0 -4
  102. package/dist/utils/get-longest-label.d.ts +0 -4
  103. package/dist/utils/merge-types.d.ts +0 -4
  104. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  105. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  106. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,67 +1,724 @@
1
- import type { PailServerType } from "./pail.d.ts";
2
- import type { ServerConstructorOptions } from "./types.d.ts";
1
+ import { InteractiveManager } from '@visulima/interactive-manager';
2
+ import { stringify } from 'safe-stable-stringify';
3
+ import { M as Meta, D as DefaultLogTypes, L as LiteralUnion, a as LoggerTypesConfig, P as Processor, E as ExtendedRfc5424LogLevels, R as Reporter, b as LoggerFunction, C as ConstructorOptions, S as ServerConstructorOptions } from "./packem_shared/types.d-CM5ie2qm.js";
4
+ export { type c as DefaultLoggerTypes, type d as LoggerConfiguration, type e as LoggerTypesAwareReporter, type f as StreamAwareReporter } from "./packem_shared/types.d-CM5ie2qm.js";
5
+ import '@visulima/colorize';
3
6
  /**
4
- * Creates a new Pail logger instance configured for server environments.
5
- *
6
- * This factory function creates a server-compatible logger with default processors
7
- * and reporters suitable for Node.js environments. It automatically configures
8
- * log levels based on environment variables and sets up pretty printing.
9
- * @template T - Custom logger types
10
- * @template L - Log level types
11
- * @param options Configuration options for the logger
12
- * @returns A new PailServer instance
13
- * @example
14
- * ```typescript
15
- * import { createPail } from "@visulima/pail";
16
- *
17
- * const logger = createPail({
18
- * logLevel: "debug",
19
- * types: {
20
- * http: {
21
- * color: "blue",
22
- * label: "HTTP",
23
- * logLevel: "info"
24
- * }
25
- * }
26
- * });
27
- *
28
- * logger.info("Server started on port 3000");
29
- * logger.http("GET /api/users 200");
30
- * ```
31
- * @example
32
- * ```bash
33
- * # Control log level via environment variable
34
- * PAIL_LOG_LEVEL=debug node app.js
35
- * ```
36
- */
37
- export declare const createPail: <T extends string = string, L extends string = string>(options?: ServerConstructorOptions<T, L>) => PailServerType<T, L>;
7
+ * Pail Browser Implementation.
8
+ *
9
+ * A comprehensive logging library for browser environments with support for
10
+ * multiple log levels, custom types, processors, reporters, and advanced features
11
+ * like throttling, scoping, timers, and counters.
12
+ * @template T - Custom logger types (string union)
13
+ * @template L - Log level types (string union)
14
+ * @example
15
+ * ```typescript
16
+ * const logger = new PailBrowserImpl({
17
+ * logLevel: "debug",
18
+ * types: {
19
+ * http: { color: "blue", label: "HTTP", logLevel: "info" }
20
+ * },
21
+ * reporters: [new JsonReporter()]
22
+ * });
23
+ *
24
+ * logger.info("Application started");
25
+ * logger.http("GET /api/users 200");
26
+ * logger.error("Something went wrong", error);
27
+ * ```
28
+ */
29
+ declare class PailBrowserImpl<T extends string = string, L extends string = string> {
30
+ #private;
31
+ protected timersMap: Map<string, number>;
32
+ protected countMap: Map<string, number>;
33
+ protected seqTimers: Set<string>;
34
+ protected readonly lastLog: {
35
+ count?: number;
36
+ object?: Meta<L>;
37
+ time?: Date;
38
+ timeout?: ReturnType<typeof setTimeout>;
39
+ };
40
+ protected readonly logLevels: Record<string, number>;
41
+ protected disabled: boolean;
42
+ protected paused: boolean;
43
+ protected messageQueue: {
44
+ messageObject: any[];
45
+ raw: boolean;
46
+ type: LiteralUnion<DefaultLogTypes, T>;
47
+ }[];
48
+ protected scopeName: string[];
49
+ protected readonly types: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>;
50
+ protected readonly longestLabel: string;
51
+ protected readonly processors: Set<Processor<L>>;
52
+ protected readonly generalLogLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
53
+ protected reporters: Set<Reporter<L>>;
54
+ protected readonly throttle: number;
55
+ protected readonly throttleMin: number;
56
+ protected readonly stringify: typeof stringify;
57
+ protected groups: string[];
58
+ protected readonly startTimerMessage: string;
59
+ protected readonly endTimerMessage: string;
60
+ protected rawReporter: Reporter<L>;
61
+ protected force: Record<string, LoggerFunction>;
62
+ /**
63
+ * Creates a new Pail browser logger instance.
64
+ *
65
+ * Initializes the logger with the provided configuration options,
66
+ * setting up reporters, processors, log levels, and other internal state.
67
+ * @param options Configuration options for the logger
68
+ */
69
+ constructor(options: ConstructorOptions<T, L>);
70
+ /**
71
+ * Wraps the global console methods to redirect them through the logger.
72
+ *
73
+ * This method replaces console methods (log, info, warn, error, etc.) with
74
+ * calls to the corresponding logger methods. The original console methods
75
+ * are backed up and can be restored using restoreConsole().
76
+ * @example
77
+ * ```typescript
78
+ * const logger = createPail();
79
+ * logger.wrapConsole();
80
+ *
81
+ * console.log("This will go through the logger");
82
+ * console.error("This too!");
83
+ *
84
+ * logger.restoreConsole(); // Restore original console methods
85
+ * ```
86
+ */
87
+ wrapConsole(): void;
88
+ /**
89
+ * Restores the original global console methods.
90
+ *
91
+ * This method restores the console methods that were backed up by wrapConsole().
92
+ * After calling this, console methods will work as they did before wrapping.
93
+ * @example
94
+ * ```typescript
95
+ * const logger = createPail();
96
+ * logger.wrapConsole();
97
+ *
98
+ * // Console methods are now wrapped
99
+ * logger.restoreConsole();
100
+ * // Console methods are restored to original behavior
101
+ * ```
102
+ */
103
+ restoreConsole(): void;
104
+ /**
105
+ * Wraps uncaught exception and unhandled rejection handlers.
106
+ *
107
+ * This method sets up global error handlers that will log uncaught exceptions
108
+ * and unhandled promise rejections through the logger. This is useful for
109
+ * capturing and logging application crashes.
110
+ * @example
111
+ * ```typescript
112
+ * const logger = createPail();
113
+ * logger.wrapException();
114
+ *
115
+ * // Now uncaught errors will be logged
116
+ * throw new Error("This will be logged");
117
+ * ```
118
+ */
119
+ wrapException(): void;
120
+ /**
121
+ * Disables all logging output.
122
+ *
123
+ * When disabled, all log calls will be silently ignored and no output
124
+ * will be produced by any reporters. This can be useful for temporarily
125
+ * suppressing log output in production or during testing.
126
+ * @example
127
+ * ```typescript
128
+ * const logger = createPail();
129
+ * logger.disable();
130
+ * logger.info("This won't be logged"); // Silent
131
+ * logger.enable();
132
+ * logger.info("This will be logged"); // Output produced
133
+ * ```
134
+ */
135
+ disable(): void;
136
+ /**
137
+ * Enables logging output.
138
+ *
139
+ * Re-enables logging after it has been disabled. All subsequent log calls
140
+ * will produce output according to the configured reporters.
141
+ * @example
142
+ * ```typescript
143
+ * const logger = createPail();
144
+ * logger.disable();
145
+ * logger.info("This won't be logged");
146
+ * logger.enable(); // Re-enable logging
147
+ * logger.info("This will be logged");
148
+ * ```
149
+ */
150
+ enable(): void;
151
+ /**
152
+ * Checks if logging is currently enabled.
153
+ *
154
+ * Returns true if logging is enabled and false if it has been disabled.
155
+ * @returns True if logging is enabled, false if disabled
156
+ * @example
157
+ * ```typescript
158
+ * const logger = createPail();
159
+ * console.log(logger.isEnabled()); // true
160
+ * logger.disable();
161
+ * console.log(logger.isEnabled()); // false
162
+ * ```
163
+ */
164
+ isEnabled(): boolean;
165
+ /**
166
+ * Pauses logging and starts queuing messages.
167
+ *
168
+ * When paused, all log calls will be queued instead of being output immediately.
169
+ * The queued messages will be processed when resume() is called. This is useful
170
+ * for temporarily buffering log output during critical operations.
171
+ * @example
172
+ * ```typescript
173
+ * const logger = createPail();
174
+ * logger.pause();
175
+ * logger.info("This will be queued"); // Queued, not output yet
176
+ * logger.warn("This too"); // Also queued
177
+ * logger.resume(); // Now both messages are output
178
+ * ```
179
+ */
180
+ pause(): void;
181
+ /**
182
+ * Resumes logging and flushes all queued messages.
183
+ *
184
+ * Processes all messages that were queued during the pause period and
185
+ * resumes normal logging behavior. Messages are output in the order
186
+ * they were originally called.
187
+ * @example
188
+ * ```typescript
189
+ * const logger = createPail();
190
+ * logger.pause();
191
+ * logger.info("Message 1"); // Queued
192
+ * logger.info("Message 2"); // Queued
193
+ * logger.resume(); // Both messages are now output in order
194
+ * logger.info("Message 3"); // Output immediately
195
+ * ```
196
+ */
197
+ resume(): void;
198
+ /**
199
+ * Creates a scoped logger instance.
200
+ *
201
+ * Returns a new logger instance that inherits all configuration but adds
202
+ * the specified scope names to all log messages. This is useful for
203
+ * categorizing logs by component, module, or feature.
204
+ * @template N - The new custom logger type names
205
+ * @param name Scope names to apply to all log messages
206
+ * @returns A new scoped logger instance
207
+ * @throws {Error} If no scope name is provided
208
+ * @example
209
+ * ```typescript
210
+ * const logger = createPail();
211
+ * const scopedLogger = logger.scope("auth", "login");
212
+ * scopedLogger.info("User logged in"); // Will include scope: ["auth", "login"]
213
+ * ```
214
+ */
215
+ scope<N extends string = T>(...name: string[]): PailBrowserType<N, L>;
216
+ /**
217
+ * Removes the current scope from the logger.
218
+ *
219
+ * Clears all scope names that were set by previous scope() calls.
220
+ * After calling this, log messages will no longer include scope information.
221
+ * @example
222
+ * ```typescript
223
+ * const logger = createPail();
224
+ * const scopedLogger = logger.scope("auth");
225
+ * scopedLogger.info("Scoped message"); // Has scope
226
+ * scopedLogger.unscope();
227
+ * scopedLogger.info("Unscoped message"); // No scope
228
+ * ```
229
+ */
230
+ unscope(): void;
231
+ /**
232
+ * Creates a child logger that inherits settings from the parent.
233
+ *
234
+ * Returns a new logger instance that inherits all configuration from the parent
235
+ * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
236
+ * you to override only what you need. Child loggers are independent instances with
237
+ * their own state (timers, counters, etc.).
238
+ * @template N - The new custom logger type names
239
+ * @template LC - The new log level types
240
+ * @param options Configuration options to override or extend parent settings
241
+ * @returns A new child logger instance
242
+ * @example
243
+ * ```typescript
244
+ * const parent = createPail({
245
+ * logLevel: "info",
246
+ * types: { http: { label: "HTTP", logLevel: "info" } },
247
+ * reporters: [new PrettyReporter()],
248
+ * });
249
+ *
250
+ * // Child inherits parent settings but overrides log level
251
+ * const child = parent.child({ logLevel: "debug" });
252
+ * child.info("This will be logged"); // Uses debug level from child
253
+ * child.http("GET /api 200"); // Inherits http type from parent
254
+ *
255
+ * // Child can add new types
256
+ * const childWithNewType = parent.child({
257
+ * types: { db: { label: "DB", logLevel: "info" } },
258
+ * });
259
+ * childWithNewType.db("Query executed"); // New type available
260
+ * ```
261
+ */
262
+ child<N extends string = T, LC extends string = L>(options?: Partial<ConstructorOptions<N, LC>>): PailBrowserType<N, LC>;
263
+ /**
264
+ * Starts a timer with the specified label.
265
+ *
266
+ * Records the current timestamp and associates it with the given label.
267
+ * Multiple timers can be active simultaneously with different labels.
268
+ * @param label The timer label (defaults to "default")
269
+ * @example
270
+ * ```typescript
271
+ * const logger = createPail();
272
+ * logger.time("operation");
273
+ * // ... some operation ...
274
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
275
+ * ```
276
+ */
277
+ time(label?: string): void;
278
+ /**
279
+ * Logs the current elapsed time for a timer without stopping it.
280
+ *
281
+ * Calculates and logs the time elapsed since the timer was started,
282
+ * but keeps the timer running. If no label is provided, uses the
283
+ * most recently started timer.
284
+ * @param label The timer label (uses last timer if not specified)
285
+ * @param data Additional data to include in the log message
286
+ * @example
287
+ * ```typescript
288
+ * const logger = createPail();
289
+ * logger.time("task");
290
+ * // ... some work ...
291
+ * logger.timeLog("task"); // Logs current elapsed time
292
+ * // ... more work ...
293
+ * logger.timeEnd("task"); // Logs final time and stops timer
294
+ * ```
295
+ */
296
+ timeLog(label?: string, ...data: unknown[]): void;
297
+ /**
298
+ * Stops a timer and logs the final elapsed time.
299
+ *
300
+ * Calculates the total time elapsed since the timer was started,
301
+ * logs the result, and removes the timer. If no label is provided,
302
+ * uses the most recently started timer.
303
+ * @param label The timer label (uses last timer if not specified)
304
+ * @example
305
+ * ```typescript
306
+ * const logger = createPail();
307
+ * logger.time("operation");
308
+ * // ... perform operation ...
309
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
310
+ * ```
311
+ */
312
+ timeEnd(label?: string): void;
313
+ /**
314
+ * Starts a log group with the specified label.
315
+ *
316
+ * Groups related log messages together. In browser environments,
317
+ * this uses the native console.group() functionality. In other
318
+ * environments, it tracks group nesting internally.
319
+ * @param label The group label (defaults to "console.group")
320
+ * @example
321
+ * ```typescript
322
+ * const logger = createPail();
323
+ * logger.group("Database Operations");
324
+ * logger.info("Connecting to database");
325
+ * logger.info("Running migration");
326
+ * logger.groupEnd(); // End the group
327
+ * ```
328
+ */
329
+ group(label?: string): void;
330
+ /**
331
+ * Ends the current log group.
332
+ *
333
+ * Closes the most recently opened log group. In browser environments,
334
+ * this uses the native console.groupEnd() functionality.
335
+ * @example
336
+ * ```typescript
337
+ * const logger = createPail();
338
+ * logger.group("Processing");
339
+ * logger.info("Step 1");
340
+ * logger.info("Step 2");
341
+ * logger.groupEnd(); // Closes the "Processing" group
342
+ * ```
343
+ */
344
+ groupEnd(): void;
345
+ /**
346
+ * Increments and logs a counter with the specified label.
347
+ *
348
+ * Maintains an internal counter for each label and logs the current count
349
+ * each time it's called. Useful for tracking how many times certain
350
+ * code paths are executed.
351
+ * @param label The counter label (defaults to "default")
352
+ * @example
353
+ * ```typescript
354
+ * const logger = createPail();
355
+ * logger.count("requests"); // Logs: "requests: 1"
356
+ * logger.count("requests"); // Logs: "requests: 2"
357
+ * logger.count("errors"); // Logs: "errors: 1"
358
+ * ```
359
+ */
360
+ count(label?: string): void;
361
+ /**
362
+ * Resets a counter to zero.
363
+ *
364
+ * Removes the counter with the specified label, effectively resetting
365
+ * it to zero. If the counter doesn't exist, logs a warning.
366
+ * @param label The counter label to reset (defaults to "default")
367
+ * @example
368
+ * ```typescript
369
+ * const logger = createPail();
370
+ * logger.count("requests"); // Logs: "requests: 1"
371
+ * logger.countReset("requests"); // Resets counter
372
+ * logger.count("requests"); // Logs: "requests: 1" (starts over)
373
+ * ```
374
+ */
375
+ countReset(label?: string): void;
376
+ /**
377
+ * Clears the console output.
378
+ *
379
+ * Calls the native console.clear() method to clear all output from
380
+ * the console. This is a convenience method that wraps the native
381
+ * console.clear() functionality.
382
+ * @example
383
+ * ```typescript
384
+ * const logger = createPail();
385
+ * logger.info("Some message");
386
+ * logger.clear(); // Clears the console
387
+ * ```
388
+ */
389
+ clear(): void;
390
+ /**
391
+ * Logs a raw message bypassing normal processing.
392
+ *
393
+ * Sends a message directly to the raw reporter without going through
394
+ * the normal logging pipeline (processors, throttling, etc.). This is
395
+ * useful for logging that needs to bypass all formatting and processing.
396
+ * @param message The raw message to log
397
+ * @param arguments_ Additional arguments to include
398
+ * @example
399
+ * ```typescript
400
+ * const logger = createPail();
401
+ * logger.raw("Direct message", { data: "value" });
402
+ * ```
403
+ */
404
+ raw(message: string, ...arguments_: unknown[]): void;
405
+ protected extendReporter(reporter: Reporter<L>): Reporter<L>;
406
+ protected registerReporters(reporters: Reporter<L>[]): void;
407
+ protected registerProcessors(processors: Processor<L>[]): void;
408
+ protected logger(type: LiteralUnion<DefaultLogTypes, T>, raw: boolean, force: boolean, ...messageObject: unknown[]): void;
409
+ }
410
+ 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> & {
411
+ force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
412
+ };
413
+ declare class PailServerImpl<T extends string = string, L extends string = string> extends PailBrowserImpl<T, L> {
414
+ #private;
415
+ readonly options: ServerConstructorOptions<T, L>;
416
+ protected readonly stdout: NodeJS.WriteStream;
417
+ protected readonly stderr: NodeJS.WriteStream;
418
+ protected interactiveManager: InteractiveManager | undefined;
419
+ protected readonly interactive: boolean;
420
+ /**
421
+ * Creates a new Pail server logger instance.
422
+ *
423
+ * Initializes the server-compatible logger with streams, interactive support,
424
+ * and server-specific configuration options.
425
+ * @param options Server-specific configuration options
426
+ */
427
+ constructor(options: ServerConstructorOptions<T, L>);
428
+ override scope<N extends string = T>(...name: string[]): PailServerType<N, L>;
429
+ /**
430
+ * Creates a child logger that inherits settings from the parent.
431
+ *
432
+ * Returns a new logger instance that inherits all configuration from the parent
433
+ * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
434
+ * you to override only what you need. Child loggers are independent instances with
435
+ * their own state (timers, counters, etc.).
436
+ * @template N - The new custom logger type names
437
+ * @template LC - The new log level types
438
+ * @param options Configuration options to override or extend parent settings
439
+ * @returns A new child logger instance
440
+ * @example
441
+ * ```typescript
442
+ * const parent = createPail({
443
+ * logLevel: "info",
444
+ * types: { http: { label: "HTTP", logLevel: "info" } },
445
+ * reporters: [new PrettyReporter()],
446
+ * });
447
+ *
448
+ * // Child inherits parent settings but overrides log level
449
+ * const child = parent.child({ logLevel: "debug" });
450
+ * child.info("This will be logged"); // Uses debug level from child
451
+ * child.http("GET /api 200"); // Inherits http type from parent
452
+ *
453
+ * // Child can add new types
454
+ * const childWithNewType = parent.child({
455
+ * types: { db: { label: "DB", logLevel: "info" } },
456
+ * });
457
+ * childWithNewType.db("Query executed"); // New type available
458
+ * ```
459
+ */
460
+ 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>;
461
+ /**
462
+ * Gets the interactive manager instance if interactive mode is enabled.
463
+ *
464
+ * Returns the InteractiveManager instance that handles interactive terminal
465
+ * features like progress bars and dynamic updates. Only available when
466
+ * interactive mode is enabled in the constructor options.
467
+ * @returns The interactive manager instance, or undefined if not in interactive mode
468
+ * @example
469
+ * ```typescript
470
+ * const logger = createPail({ interactive: true });
471
+ * const manager = logger.getInteractiveManager();
472
+ * if (manager) {
473
+ * manager.hook();
474
+ * // Use interactive features
475
+ * manager.unhook();
476
+ * }
477
+ * ```
478
+ */
479
+ getInteractiveManager(): InteractiveManager | undefined;
480
+ /**
481
+ * Wraps stdout and stderr streams to redirect them through the logger.
482
+ *
483
+ * Intercepts writes to process.stdout and process.stderr, redirecting them
484
+ * through the logger instead of writing directly to the streams. This allows
485
+ * all output to be processed by the logging pipeline.
486
+ * @example
487
+ * ```typescript
488
+ * const logger = createPail();
489
+ * logger.wrapStd();
490
+ *
491
+ * console.log("This goes through logger");
492
+ * process.stdout.write("This too");
493
+ *
494
+ * logger.restoreStd(); // Restore original streams
495
+ * ```
496
+ */
497
+ wrapStd(): void;
498
+ /**
499
+ * Restores the original stdout and stderr streams.
500
+ *
501
+ * Removes the stream wrapping that was applied by wrapStd(),
502
+ * restoring the original stream write methods.
503
+ * @example
504
+ * ```typescript
505
+ * const logger = createPail();
506
+ * logger.wrapStd();
507
+ * // Streams are wrapped
508
+ * logger.restoreStd();
509
+ * // Streams are restored to original behavior
510
+ * ```
511
+ */
512
+ restoreStd(): void;
513
+ /**
514
+ * Wraps all output sources (console and streams).
515
+ *
516
+ * Convenience method that calls both wrapConsole() and wrapStd()
517
+ * to redirect all output through the logger.
518
+ * @example
519
+ * ```typescript
520
+ * const logger = createPail();
521
+ * logger.wrapAll(); // Wraps console and streams
522
+ *
523
+ * // All output now goes through logger
524
+ * console.log("Console output");
525
+ * process.stdout.write("Stream output");
526
+ *
527
+ * logger.restoreAll(); // Restore everything
528
+ * ```
529
+ */
530
+ wrapAll(): void;
531
+ /**
532
+ * Restores all wrapped output sources.
533
+ *
534
+ * Convenience method that calls both restoreConsole() and restoreStd()
535
+ * to restore all original output behavior.
536
+ * @example
537
+ * ```typescript
538
+ * const logger = createPail();
539
+ * logger.wrapAll();
540
+ * // All output is wrapped
541
+ * logger.restoreAll();
542
+ * // All output sources are restored
543
+ * ```
544
+ */
545
+ restoreAll(): void;
546
+ /**
547
+ * Clears the terminal screen.
548
+ *
549
+ * Sends ANSI escape sequences to clear the terminal screen and move
550
+ * the cursor to the top-left position. This overrides the browser
551
+ * implementation to work with terminal streams.
552
+ * @example
553
+ * ```typescript
554
+ * const logger = createPail();
555
+ * logger.info("Some output");
556
+ * logger.clear(); // Clears the terminal screen
557
+ * ```
558
+ */
559
+ override clear(): void;
560
+ protected override extendReporter(reporter: Reporter<L>): Reporter<L>;
561
+ }
562
+ 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> & {
563
+ force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
564
+ };
38
565
  /**
39
- * Default Pail logger instance for server environments.
40
- *
41
- * A pre-configured logger instance ready for immediate use in Node.js environments.
42
- * Uses default configuration with pretty reporter, message formatter processor,
43
- * and automatic log level detection based on environment variables.
44
- * @example
45
- * ```typescript
46
- * import { pail } from "@visulima/pail";
47
- *
48
- * pail.info("Server listening on port 3000");
49
- * pail.error("Database connection failed", error);
50
- * pail.success("Migration completed successfully");
51
- * ```
52
- * @example
53
- * ```bash
54
- * # Set log level via environment
55
- * NODE_ENV=production node app.js
56
- * PAIL_LOG_LEVEL=debug node app.js
57
- * ```
58
- */
59
- export declare const pail: PailServerType;
60
- export type { PailErrorOptions } from "./error.d.ts";
61
- export { createPailError, PailError } from "./error.d.ts";
62
- export type { PailServerType as Pail } from "./pail.d.ts";
63
- export type { MultiBarOptions, ProgressBarOptions, ProgressBarPayload, ProgressBarStyle, SingleBarOptions } from "./progress-bar.d.ts";
64
- export { getBarChar, MultiProgressBar, ProgressBar } from "./progress-bar.d.ts";
65
- export type { SpinnerIcons, SpinnerOptions, SpinnerStartOptions, SpinnerStyle } from "./spinner.d.ts";
66
- export { MultiSpinner, Spinner } from "./spinner.d.ts";
67
- export type { ConstructorOptions, DefaultLoggerTypes, DefaultLogTypes, ExtendedRfc5424LogLevels, LoggerConfiguration, LoggerFunction, LoggerTypesAwareReporter, LoggerTypesConfig, Processor, Reporter, StreamAwareReporter, } from "./types.d.ts";
566
+ * Options for creating a PailError.
567
+ *
568
+ * Extends standard error properties with self-documenting fields
569
+ * that provide actionable context for debugging, particularly useful
570
+ * for AI-assisted log analysis.
571
+ */
572
+ interface PailErrorOptions {
573
+ /** The root cause of this error */
574
+ cause?: unknown;
575
+ /** A suggested resolution or steps to fix the issue */
576
+ fix?: string;
577
+ /** A link to relevant documentation or issue tracker */
578
+ link?: string;
579
+ /** The error message */
580
+ message: string;
581
+ /** HTTP status code associated with this error */
582
+ status?: number;
583
+ /** An explanation of what caused the failure */
584
+ why?: string;
585
+ }
586
+ /**
587
+ * Self-documenting error class for structured logging.
588
+ *
589
+ * Inspired by evlog's structured error approach, PailError extends the native
590
+ * Error class with additional fields that make log entries immediately actionable:
591
+ * - `why`: Explains what caused the failure
592
+ * - `fix`: Suggests how to resolve the issue
593
+ * - `link`: Points to relevant documentation
594
+ * - `status`: HTTP status code for request-related errors
595
+ *
596
+ * These fields are preserved through the logging pipeline and displayed by reporters,
597
+ * making it easier for both humans and AI agents to understand and resolve issues.
598
+ * @example
599
+ * ```typescript
600
+ * import { PailError, createPailError } from "@visulima/pail/error";
601
+ *
602
+ * // Using the class directly
603
+ * throw new PailError({
604
+ * message: "Payment processing failed",
605
+ * status: 402,
606
+ * why: "The customer's card was declined by the payment provider",
607
+ * fix: "Retry with a different payment method or contact the card issuer",
608
+ * link: "https://docs.example.com/payments/declined",
609
+ * });
610
+ *
611
+ * // Using the factory function
612
+ * throw createPailError("Connection timeout");
613
+ *
614
+ * // With full options
615
+ * throw createPailError({
616
+ * message: "Database connection failed",
617
+ * why: "Connection pool exhausted after 30s timeout",
618
+ * fix: "Increase pool size or check for connection leaks",
619
+ * });
620
+ * ```
621
+ */
622
+ declare class PailError extends Error {
623
+ /** HTTP status code (defaults to 500) */
624
+ readonly status: number;
625
+ /** Explanation of what caused the failure */
626
+ readonly why: string | undefined;
627
+ /** Suggested resolution steps */
628
+ readonly fix: string | undefined;
629
+ /** Link to relevant documentation */
630
+ readonly link: string | undefined;
631
+ constructor(options: PailErrorOptions | string);
632
+ /**
633
+ * Converts the error to a JSON-serializable object.
634
+ *
635
+ * Includes all self-documenting fields in the output for structured logging.
636
+ * @returns A plain object representation of the error
637
+ */
638
+ toJSON(): Record<string, unknown>;
639
+ /**
640
+ * Returns a formatted string representation including self-documenting fields.
641
+ * @returns Formatted error string with why/fix/link context
642
+ */
643
+ override toString(): string;
644
+ }
645
+ /**
646
+ * Factory function for creating PailError instances.
647
+ *
648
+ * A convenient shorthand for creating PailError objects. Accepts either
649
+ * a string message or a full PailErrorOptions object.
650
+ * @param options Error message string or PailErrorOptions object
651
+ * @returns A new PailError instance
652
+ * @example
653
+ * ```typescript
654
+ * import { createPailError } from "@visulima/pail/error";
655
+ *
656
+ * throw createPailError("Something went wrong");
657
+ *
658
+ * throw createPailError({
659
+ * message: "Auth failed",
660
+ * status: 401,
661
+ * why: "Token expired",
662
+ * fix: "Refresh the authentication token",
663
+ * });
664
+ * ```
665
+ */
666
+ declare const createPailError: (options: PailErrorOptions | string) => PailError;
667
+ /**
668
+ * Creates a new Pail logger instance configured for server environments.
669
+ *
670
+ * This factory function creates a server-compatible logger with default processors
671
+ * and reporters suitable for Node.js environments. It automatically configures
672
+ * log levels based on environment variables and sets up pretty printing.
673
+ * @template T - Custom logger types
674
+ * @template L - Log level types
675
+ * @param options Configuration options for the logger
676
+ * @returns A new PailServer instance
677
+ * @example
678
+ * ```typescript
679
+ * import { createPail } from "@visulima/pail";
680
+ *
681
+ * const logger = createPail({
682
+ * logLevel: "debug",
683
+ * types: {
684
+ * http: {
685
+ * color: "blue",
686
+ * label: "HTTP",
687
+ * logLevel: "info"
688
+ * }
689
+ * }
690
+ * });
691
+ *
692
+ * logger.info("Server started on port 3000");
693
+ * logger.http("GET /api/users 200");
694
+ * ```
695
+ * @example
696
+ * ```bash
697
+ * # Control log level via environment variable
698
+ * PAIL_LOG_LEVEL=debug node app.js
699
+ * ```
700
+ */
701
+ declare const createPail: <T extends string = string, L extends string = string>(options?: ServerConstructorOptions<T, L>) => PailServerType<T, L>;
702
+ /**
703
+ * Default Pail logger instance for server environments.
704
+ *
705
+ * A pre-configured logger instance ready for immediate use in Node.js environments.
706
+ * Uses default configuration with pretty reporter, message formatter processor,
707
+ * and automatic log level detection based on environment variables.
708
+ * @example
709
+ * ```typescript
710
+ * import { pail } from "@visulima/pail";
711
+ *
712
+ * pail.info("Server listening on port 3000");
713
+ * pail.error("Database connection failed", error);
714
+ * pail.success("Migration completed successfully");
715
+ * ```
716
+ * @example
717
+ * ```bash
718
+ * # Set log level via environment
719
+ * NODE_ENV=production node app.js
720
+ * PAIL_LOG_LEVEL=debug node app.js
721
+ * ```
722
+ */
723
+ declare const pail: PailServerType;
724
+ export { type ConstructorOptions, type DefaultLogTypes, type ExtendedRfc5424LogLevels, type LoggerFunction, type LoggerTypesConfig, type PailServerType as Pail, PailError, type PailErrorOptions, type Processor, type Reporter, createPail, createPailError, pail };