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