@visulima/pail 4.0.0-alpha.11 → 4.0.0-alpha.13

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