@visulima/pail 4.0.0-alpha.2 → 4.0.0-alpha.20

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