@visulima/pail 4.0.0-alpha.9 → 4.0.0

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