@visulima/pail 4.0.0-alpha.9 → 4.0.1

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 +519 -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 +43 -58
  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,49 +1,570 @@
1
- import type { PailBrowserType } from "./pail.d.ts";
2
- import type { ConstructorOptions } from "./types.d.ts";
1
+ import { s as stringify } from "./packem_shared/index.d-T71KjNAr.js";
2
+ import { C as ConstructorOptions, M as Meta, D as DefaultLogTypes, L as LiteralUnion, a as LoggerTypesConfig, P as Processor, E as ExtendedRfc5424LogLevels, c as Reporter, d as LoggerFunction } from "./packem_shared/types.d-xxE3FOD3.js";
3
+ export type { e as DefaultLoggerTypes, f as LoggerConfiguration, b as LoggerTypesAwareReporter, g as StreamAwareReporter } from "./packem_shared/types.d-xxE3FOD3.js";
4
+ import '@visulima/colorize';
5
+ import '@visulima/interactive-manager';
3
6
  /**
4
- * Creates a new Pail logger instance configured for browser environments.
5
- *
6
- * This factory function creates a browser-compatible logger with default processors
7
- * and reporters suitable for client-side logging.
8
- * @template T - Custom logger types
9
- * @template L - Log level types
10
- * @param options Configuration options for the logger
11
- * @returns A new PailBrowser instance
12
- * @example
13
- * ```typescript
14
- * import { createPail } from "@visulima/pail";
15
- *
16
- * const logger = createPail({
17
- * logLevel: "debug",
18
- * types: {
19
- * custom: {
20
- * color: "blue",
21
- * label: "CUSTOM",
22
- * logLevel: "info"
23
- * }
24
- * }
25
- * });
26
- *
27
- * logger.info("Hello world!");
28
- * logger.custom("Custom message");
29
- * ```
30
- */
31
- export declare const createPail: <T extends string = string, L extends string = string>(options?: ConstructorOptions<T, L>) => PailBrowserType<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 readonly lastLog: {
32
+ count?: number;
33
+ object?: Meta<L>;
34
+ signature?: string;
35
+ time?: Date;
36
+ timeout?: ReturnType<typeof setTimeout>;
37
+ };
38
+ protected readonly logLevels: Record<string, number>;
39
+ protected disabled: boolean;
40
+ protected paused: boolean;
41
+ protected messageQueue: {
42
+ messageObject: any[];
43
+ raw: boolean;
44
+ type: LiteralUnion<DefaultLogTypes, T>;
45
+ }[];
46
+ protected scopeName: string[];
47
+ protected readonly types: LoggerTypesConfig<LiteralUnion<DefaultLogTypes, T>, L>;
48
+ protected readonly longestLabel: string;
49
+ protected readonly processors: Set<Processor<L>>;
50
+ protected readonly generalLogLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
51
+ protected reporters: Set<Reporter<L>>;
52
+ protected readonly throttle: number;
53
+ protected readonly throttleMin: number;
54
+ protected readonly stringify: typeof stringify;
55
+ protected groups: string[];
56
+ protected readonly startTimerMessage: string;
57
+ protected readonly endTimerMessage: string;
58
+ protected rawReporter: Reporter<L>;
59
+ protected force: Record<string, LoggerFunction>;
60
+ /**
61
+ * Creates a new Pail browser logger instance.
62
+ *
63
+ * Initializes the logger with the provided configuration options,
64
+ * setting up reporters, processors, log levels, and other internal state.
65
+ * @param options Configuration options for the logger
66
+ */
67
+ constructor(options: ConstructorOptions<T, L>);
68
+ /**
69
+ * Wraps the global console methods to redirect them through the logger.
70
+ *
71
+ * This method replaces console methods (log, info, warn, error, etc.) with
72
+ * calls to the corresponding logger methods. The original console methods
73
+ * are backed up and can be restored using restoreConsole().
74
+ * @example
75
+ * ```typescript
76
+ * const logger = createPail();
77
+ * logger.wrapConsole();
78
+ *
79
+ * console.log("This will go through the logger");
80
+ * console.error("This too!");
81
+ *
82
+ * logger.restoreConsole(); // Restore original console methods
83
+ * ```
84
+ */
85
+ wrapConsole(): void;
86
+ /**
87
+ * Restores the original global console methods.
88
+ *
89
+ * This method restores the console methods that were backed up by wrapConsole().
90
+ * After calling this, console methods will work as they did before wrapping.
91
+ * @example
92
+ * ```typescript
93
+ * const logger = createPail();
94
+ * logger.wrapConsole();
95
+ *
96
+ * // Console methods are now wrapped
97
+ * logger.restoreConsole();
98
+ * // Console methods are restored to original behavior
99
+ * ```
100
+ */
101
+ restoreConsole(): void;
102
+ /**
103
+ * Wraps uncaught exception and unhandled rejection handlers.
104
+ *
105
+ * This method sets up global error handlers that will log uncaught exceptions
106
+ * and unhandled promise rejections through the logger. This is useful for
107
+ * capturing and logging application crashes.
108
+ * @example
109
+ * ```typescript
110
+ * const logger = createPail();
111
+ * logger.wrapException();
112
+ *
113
+ * // Now uncaught errors will be logged
114
+ * throw new Error("This will be logged");
115
+ * ```
116
+ */
117
+ wrapException(): void;
118
+ /**
119
+ * Removes the global exception/rejection handlers installed by {@link wrapException}.
120
+ *
121
+ * Counterpart to `wrapException()` (mirrors `wrapConsole()`/`restoreConsole()`).
122
+ * Safe to call when no handlers are installed.
123
+ * @example
124
+ * ```typescript
125
+ * const logger = createPail();
126
+ * logger.wrapException();
127
+ * // ... later ...
128
+ * logger.restoreException(); // global handlers removed
129
+ * ```
130
+ */
131
+ restoreException(): void;
132
+ /**
133
+ * Disables all logging output.
134
+ *
135
+ * When disabled, all log calls will be silently ignored and no output
136
+ * will be produced by any reporters. This can be useful for temporarily
137
+ * suppressing log output in production or during testing.
138
+ * @example
139
+ * ```typescript
140
+ * const logger = createPail();
141
+ * logger.disable();
142
+ * logger.info("This won't be logged"); // Silent
143
+ * logger.enable();
144
+ * logger.info("This will be logged"); // Output produced
145
+ * ```
146
+ */
147
+ disable(): void;
148
+ /**
149
+ * Enables logging output.
150
+ *
151
+ * Re-enables logging after it has been disabled. All subsequent log calls
152
+ * will produce output according to the configured reporters.
153
+ * @example
154
+ * ```typescript
155
+ * const logger = createPail();
156
+ * logger.disable();
157
+ * logger.info("This won't be logged");
158
+ * logger.enable(); // Re-enable logging
159
+ * logger.info("This will be logged");
160
+ * ```
161
+ */
162
+ enable(): void;
163
+ /**
164
+ * Checks if logging is currently enabled.
165
+ *
166
+ * Returns true if logging is enabled and false if it has been disabled.
167
+ * @returns True if logging is enabled, false if disabled
168
+ * @example
169
+ * ```typescript
170
+ * const logger = createPail();
171
+ * console.log(logger.isEnabled()); // true
172
+ * logger.disable();
173
+ * console.log(logger.isEnabled()); // false
174
+ * ```
175
+ */
176
+ isEnabled(): boolean;
177
+ /**
178
+ * Pauses logging and starts queuing messages.
179
+ *
180
+ * When paused, all log calls will be queued instead of being output immediately.
181
+ * The queued messages will be processed when resume() is called. This is useful
182
+ * for temporarily buffering log output during critical operations.
183
+ * @example
184
+ * ```typescript
185
+ * const logger = createPail();
186
+ * logger.pause();
187
+ * logger.info("This will be queued"); // Queued, not output yet
188
+ * logger.warn("This too"); // Also queued
189
+ * logger.resume(); // Now both messages are output
190
+ * ```
191
+ */
192
+ pause(): void;
193
+ /**
194
+ * Resumes logging and flushes all queued messages.
195
+ *
196
+ * Processes all messages that were queued during the pause period and
197
+ * resumes normal logging behavior. Messages are output in the order
198
+ * they were originally called.
199
+ * @example
200
+ * ```typescript
201
+ * const logger = createPail();
202
+ * logger.pause();
203
+ * logger.info("Message 1"); // Queued
204
+ * logger.info("Message 2"); // Queued
205
+ * logger.resume(); // Both messages are now output in order
206
+ * logger.info("Message 3"); // Output immediately
207
+ * ```
208
+ */
209
+ resume(): void;
210
+ /**
211
+ * Creates a scoped logger instance.
212
+ *
213
+ * Returns a new logger instance that inherits all configuration but adds
214
+ * the specified scope names to all log messages. This is useful for
215
+ * categorizing logs by component, module, or feature.
216
+ * @template N - The new custom logger type names
217
+ * @param name Scope names to apply to all log messages
218
+ * @returns A new scoped logger instance
219
+ * @throws {Error} If no scope name is provided
220
+ * @example
221
+ * ```typescript
222
+ * const logger = createPail();
223
+ * const scopedLogger = logger.scope("auth", "login");
224
+ * scopedLogger.info("User logged in"); // Will include scope: ["auth", "login"]
225
+ * ```
226
+ */
227
+ scope<N extends string = T>(...name: string[]): PailBrowserType<N, L>;
228
+ /**
229
+ * Removes the current scope from the logger.
230
+ *
231
+ * Clears all scope names that were set by previous scope() calls.
232
+ * After calling this, log messages will no longer include scope information.
233
+ * @example
234
+ * ```typescript
235
+ * const logger = createPail();
236
+ * const scopedLogger = logger.scope("auth");
237
+ * scopedLogger.info("Scoped message"); // Has scope
238
+ * scopedLogger.unscope();
239
+ * scopedLogger.info("Unscoped message"); // No scope
240
+ * ```
241
+ */
242
+ unscope(): void;
243
+ /**
244
+ * Creates a child logger that inherits settings from the parent.
245
+ *
246
+ * Returns a new logger instance that inherits all configuration from the parent
247
+ * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
248
+ * you to override only what you need. Child loggers are independent instances with
249
+ * their own state (timers, counters, etc.).
250
+ * @template N - The new custom logger type names
251
+ * @template LC - The new log level types
252
+ * @param options Configuration options to override or extend parent settings
253
+ * @returns A new child logger instance
254
+ * @example
255
+ * ```typescript
256
+ * const parent = createPail({
257
+ * logLevel: "info",
258
+ * types: { http: { label: "HTTP", logLevel: "info" } },
259
+ * reporters: [new PrettyReporter()],
260
+ * });
261
+ *
262
+ * // Child inherits parent settings but overrides log level
263
+ * const child = parent.child({ logLevel: "debug" });
264
+ * child.info("This will be logged"); // Uses debug level from child
265
+ * child.http("GET /api 200"); // Inherits http type from parent
266
+ *
267
+ * // Child can add new types
268
+ * const childWithNewType = parent.child({
269
+ * types: { db: { label: "DB", logLevel: "info" } },
270
+ * });
271
+ * childWithNewType.db("Query executed"); // New type available
272
+ * ```
273
+ */
274
+ child<N extends string = T, LC extends string = L>(options?: Partial<ConstructorOptions<N, LC>>): PailBrowserType<N, LC>;
275
+ /**
276
+ * Starts a timer with the specified label.
277
+ *
278
+ * Records the current timestamp and associates it with the given label.
279
+ * Multiple timers can be active simultaneously with different labels.
280
+ * @param label The timer label (defaults to "default")
281
+ * @example
282
+ * ```typescript
283
+ * const logger = createPail();
284
+ * logger.time("operation");
285
+ * // ... some operation ...
286
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
287
+ * ```
288
+ */
289
+ time(label?: string): void;
290
+ /**
291
+ * Logs the current elapsed time for a timer without stopping it.
292
+ *
293
+ * Calculates and logs the time elapsed since the timer was started,
294
+ * but keeps the timer running. If no label is provided, uses the
295
+ * most recently started timer.
296
+ * @param label The timer label (uses last timer if not specified)
297
+ * @param data Additional data to include in the log message
298
+ * @example
299
+ * ```typescript
300
+ * const logger = createPail();
301
+ * logger.time("task");
302
+ * // ... some work ...
303
+ * logger.timeLog("task"); // Logs current elapsed time
304
+ * // ... more work ...
305
+ * logger.timeEnd("task"); // Logs final time and stops timer
306
+ * ```
307
+ */
308
+ timeLog(label?: string, ...data: unknown[]): void;
309
+ /**
310
+ * Stops a timer and logs the final elapsed time.
311
+ *
312
+ * Calculates the total time elapsed since the timer was started,
313
+ * logs the result, and removes the timer. If no label is provided,
314
+ * uses the most recently started timer.
315
+ * @param label The timer label (uses last timer if not specified)
316
+ * @example
317
+ * ```typescript
318
+ * const logger = createPail();
319
+ * logger.time("operation");
320
+ * // ... perform operation ...
321
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
322
+ * ```
323
+ */
324
+ timeEnd(label?: string): void;
325
+ /**
326
+ * Starts a log group with the specified label.
327
+ *
328
+ * Groups related log messages together. In browser environments,
329
+ * this uses the native console.group() functionality. In other
330
+ * environments, it tracks group nesting internally.
331
+ * @param label The group label (defaults to "console.group")
332
+ * @example
333
+ * ```typescript
334
+ * const logger = createPail();
335
+ * logger.group("Database Operations");
336
+ * logger.info("Connecting to database");
337
+ * logger.info("Running migration");
338
+ * logger.groupEnd(); // End the group
339
+ * ```
340
+ */
341
+ group(label?: string): void;
342
+ /**
343
+ * Ends the current log group.
344
+ *
345
+ * Closes the most recently opened log group. In browser environments,
346
+ * this uses the native console.groupEnd() functionality.
347
+ * @example
348
+ * ```typescript
349
+ * const logger = createPail();
350
+ * logger.group("Processing");
351
+ * logger.info("Step 1");
352
+ * logger.info("Step 2");
353
+ * logger.groupEnd(); // Closes the "Processing" group
354
+ * ```
355
+ */
356
+ groupEnd(): void;
357
+ /**
358
+ * Increments and logs a counter with the specified label.
359
+ *
360
+ * Maintains an internal counter for each label and logs the current count
361
+ * each time it's called. Useful for tracking how many times certain
362
+ * code paths are executed.
363
+ * @param label The counter label (defaults to "default")
364
+ * @example
365
+ * ```typescript
366
+ * const logger = createPail();
367
+ * logger.count("requests"); // Logs: "requests: 1"
368
+ * logger.count("requests"); // Logs: "requests: 2"
369
+ * logger.count("errors"); // Logs: "errors: 1"
370
+ * ```
371
+ */
372
+ count(label?: string): void;
373
+ /**
374
+ * Resets a counter to zero.
375
+ *
376
+ * Removes the counter with the specified label, effectively resetting
377
+ * it to zero. If the counter doesn't exist, logs a warning.
378
+ * @param label The counter label to reset (defaults to "default")
379
+ * @example
380
+ * ```typescript
381
+ * const logger = createPail();
382
+ * logger.count("requests"); // Logs: "requests: 1"
383
+ * logger.countReset("requests"); // Resets counter
384
+ * logger.count("requests"); // Logs: "requests: 1" (starts over)
385
+ * ```
386
+ */
387
+ countReset(label?: string): void;
388
+ /**
389
+ * Clears the console output.
390
+ *
391
+ * Calls the native console.clear() method to clear all output from
392
+ * the console. This is a convenience method that wraps the native
393
+ * console.clear() functionality.
394
+ * @example
395
+ * ```typescript
396
+ * const logger = createPail();
397
+ * logger.info("Some message");
398
+ * logger.clear(); // Clears the console
399
+ * ```
400
+ */
401
+ clear(): void;
402
+ /**
403
+ * Logs a raw message bypassing normal processing.
404
+ *
405
+ * Sends a message directly to the raw reporter without going through
406
+ * the normal logging pipeline (processors, throttling, etc.). This is
407
+ * useful for logging that needs to bypass all formatting and processing.
408
+ * @param message The raw message to log
409
+ * @param arguments_ Additional arguments to include
410
+ * @example
411
+ * ```typescript
412
+ * const logger = createPail();
413
+ * logger.raw("Direct message", { data: "value" });
414
+ * ```
415
+ */
416
+ raw(message: string, ...arguments_: unknown[]): void;
417
+ protected extendReporter(reporter: Reporter<L>): Reporter<L>;
418
+ protected registerReporters(reporters: Reporter<L>[]): void;
419
+ protected registerProcessors(processors: Processor<L>[]): void;
420
+ protected logger(type: LiteralUnion<DefaultLogTypes, T>, raw: boolean, force: boolean, ...messageObject: unknown[]): void;
421
+ }
422
+ 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> & {
423
+ force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
424
+ };
32
425
  /**
33
- * Default Pail logger instance for browser environments.
34
- *
35
- * A pre-configured logger instance ready for immediate use in browser environments.
36
- * Uses default configuration with JSON reporter and message formatter processor.
37
- * @example
38
- * ```typescript
39
- * import { pail } from "@visulima/pail";
40
- *
41
- * pail.info("Application started");
42
- * pail.error("Something went wrong", new Error("Test error"));
43
- * ```
44
- */
45
- export declare const pail: PailBrowserType<string, string>;
46
- export type { PailBrowserType as Pail } from "./pail.d.ts";
47
- export type { PailErrorOptions } from "./error.d.ts";
48
- export { createPailError, PailError } from "./error.d.ts";
49
- export type { ConstructorOptions, DefaultLoggerTypes, DefaultLogTypes, ExtendedRfc5424LogLevels, LoggerConfiguration, LoggerFunction, LoggerTypesAwareReporter, LoggerTypesConfig, Processor, Reporter, StreamAwareReporter, } from "./types.d.ts";
426
+ * Options for creating a PailError.
427
+ *
428
+ * Extends standard error properties with self-documenting fields
429
+ * that provide actionable context for debugging, particularly useful
430
+ * for AI-assisted log analysis.
431
+ */
432
+ interface PailErrorOptions {
433
+ /** The root cause of this error */
434
+ cause?: unknown;
435
+ /** A suggested resolution or steps to fix the issue */
436
+ fix?: string;
437
+ /** A link to relevant documentation or issue tracker */
438
+ link?: string;
439
+ /** The error message */
440
+ message: string;
441
+ /** HTTP status code associated with this error */
442
+ status?: number;
443
+ /** An explanation of what caused the failure */
444
+ why?: string;
445
+ }
446
+ /**
447
+ * Self-documenting error class for structured logging.
448
+ *
449
+ * Inspired by evlog's structured error approach, PailError extends the native
450
+ * Error class with additional fields that make log entries immediately actionable:
451
+ * - `why`: Explains what caused the failure
452
+ * - `fix`: Suggests how to resolve the issue
453
+ * - `link`: Points to relevant documentation
454
+ * - `status`: HTTP status code for request-related errors
455
+ *
456
+ * These fields are preserved through the logging pipeline and displayed by reporters,
457
+ * making it easier for both humans and AI agents to understand and resolve issues.
458
+ * @example
459
+ * ```typescript
460
+ * import { PailError, createPailError } from "@visulima/pail/error";
461
+ *
462
+ * // Using the class directly
463
+ * throw new PailError({
464
+ * message: "Payment processing failed",
465
+ * status: 402,
466
+ * why: "The customer's card was declined by the payment provider",
467
+ * fix: "Retry with a different payment method or contact the card issuer",
468
+ * link: "https://docs.example.com/payments/declined",
469
+ * });
470
+ *
471
+ * // Using the factory function
472
+ * throw createPailError("Connection timeout");
473
+ *
474
+ * // With full options
475
+ * throw createPailError({
476
+ * message: "Database connection failed",
477
+ * why: "Connection pool exhausted after 30s timeout",
478
+ * fix: "Increase pool size or check for connection leaks",
479
+ * });
480
+ * ```
481
+ */
482
+ declare class PailError extends Error {
483
+ /** HTTP status code (defaults to 500) */
484
+ readonly status: number;
485
+ /** Explanation of what caused the failure */
486
+ readonly why: string | undefined;
487
+ /** Suggested resolution steps */
488
+ readonly fix: string | undefined;
489
+ /** Link to relevant documentation */
490
+ readonly link: string | undefined;
491
+ constructor(options: PailErrorOptions | string);
492
+ /**
493
+ * Converts the error to a JSON-serializable object.
494
+ *
495
+ * Includes all self-documenting fields in the output for structured logging.
496
+ * @returns A plain object representation of the error
497
+ */
498
+ toJSON(): Record<string, unknown>;
499
+ /**
500
+ * Returns a formatted string representation including self-documenting fields.
501
+ * @returns Formatted error string with why/fix/link context
502
+ */
503
+ override toString(): string;
504
+ }
505
+ /**
506
+ * Factory function for creating PailError instances.
507
+ *
508
+ * A convenient shorthand for creating PailError objects. Accepts either
509
+ * a string message or a full PailErrorOptions object.
510
+ * @param options Error message string or PailErrorOptions object
511
+ * @returns A new PailError instance
512
+ * @example
513
+ * ```typescript
514
+ * import { createPailError } from "@visulima/pail/error";
515
+ *
516
+ * throw createPailError("Something went wrong");
517
+ *
518
+ * throw createPailError({
519
+ * message: "Auth failed",
520
+ * status: 401,
521
+ * why: "Token expired",
522
+ * fix: "Refresh the authentication token",
523
+ * });
524
+ * ```
525
+ */
526
+ declare const createPailError: (options: PailErrorOptions | string) => PailError;
527
+ /**
528
+ * Creates a new Pail logger instance configured for browser environments.
529
+ *
530
+ * This factory function creates a browser-compatible logger with default processors
531
+ * and reporters suitable for client-side logging.
532
+ * @template T - Custom logger types
533
+ * @template L - Log level types
534
+ * @param options Configuration options for the logger
535
+ * @returns A new PailBrowser instance
536
+ * @example
537
+ * ```typescript
538
+ * import { createPail } from "@visulima/pail";
539
+ *
540
+ * const logger = createPail({
541
+ * logLevel: "debug",
542
+ * types: {
543
+ * custom: {
544
+ * color: "blue",
545
+ * label: "CUSTOM",
546
+ * logLevel: "info"
547
+ * }
548
+ * }
549
+ * });
550
+ *
551
+ * logger.info("Hello world!");
552
+ * logger.custom("Custom message");
553
+ * ```
554
+ */
555
+ declare const createPail: <T extends string = string, L extends string = string>(options?: ConstructorOptions<T, L>) => PailBrowserType<T, L>;
556
+ /**
557
+ * Default Pail logger instance for browser environments.
558
+ *
559
+ * A pre-configured logger instance ready for immediate use in browser environments.
560
+ * Uses default configuration with JSON reporter and message formatter processor.
561
+ * @example
562
+ * ```typescript
563
+ * import { pail } from "@visulima/pail";
564
+ *
565
+ * pail.info("Application started");
566
+ * pail.error("Something went wrong", new Error("Test error"));
567
+ * ```
568
+ */
569
+ declare const pail: PailBrowserType;
570
+ export { type ConstructorOptions, type DefaultLogTypes, type ExtendedRfc5424LogLevels, type LoggerFunction, type LoggerTypesConfig, type PailBrowserType as Pail, PailError, type PailErrorOptions, type Processor, type Reporter, createPail, createPailError, pail };