@visulima/pail 4.0.0-alpha.10 → 4.0.0-alpha.12
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 +57 -0
- package/LICENSE.md +143 -931
- package/dist/error.d.ts +95 -96
- package/dist/index.browser.d.ts +557 -47
- package/dist/index.browser.js +2 -2
- package/dist/index.server.d.ts +722 -65
- package/dist/index.server.js +27 -410
- package/dist/middleware/elysia.d.ts +65 -63
- package/dist/middleware/elysia.js +2 -2
- package/dist/middleware/express.d.ts +73 -71
- package/dist/middleware/express.js +1 -1
- package/dist/middleware/fastify.d.ts +69 -67
- package/dist/middleware/fastify.js +2 -2
- package/dist/middleware/hono.d.ts +74 -72
- package/dist/middleware/next/handler.d.ts +101 -34
- package/dist/middleware/sveltekit.d.ts +100 -98
- package/dist/object-tree.d.ts +67 -70
- package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
- package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
- package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
- package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
- package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-CIbrmjUV.js} +2 -4
- package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-CNJEO9g7.js} +1250 -15
- package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
- package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CkqCt5hg.js} +2300 -2298
- package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
- package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
- package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
- package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
- package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
- package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
- package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
- package/dist/processor/caller/caller-processor.d.ts +49 -47
- package/dist/processor/caller/caller-processor.js +1 -1
- package/dist/processor/environment-processor.d.ts +113 -113
- package/dist/processor/message-formatter-processor.d.ts +51 -49
- package/dist/processor/message-formatter-processor.js +2 -2
- package/dist/processor/opentelemetry-processor.d.ts +69 -66
- package/dist/processor/redact-processor.d.ts +60 -41
- package/dist/processor/sampling-processor.d.ts +102 -101
- package/dist/reporter/file/json-file-reporter.d.ts +91 -42
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
- package/dist/reporter/http/abstract-http-reporter.js +1 -1
- package/dist/reporter/http/http-reporter.d.ts +40 -36
- package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
- package/dist/reporter/http/http-reporter.edge-light.js +1 -5
- package/dist/reporter/json/index.browser.d.ts +99 -3
- package/dist/reporter/json/index.browser.js +2 -2
- package/dist/reporter/json/index.d.ts +51 -3
- package/dist/reporter/json/index.js +2 -2
- package/dist/reporter/pretty/index.browser.d.ts +106 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +219 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
- package/dist/reporter/simple/simple-reporter.server.js +3 -2
- package/dist/wide-event.d.ts +5 -300
- package/dist/wide-event.js +3 -2
- package/package.json +9 -21
- package/dist/constants.d.ts +0 -37
- package/dist/interactive/index.d.ts +0 -2
- package/dist/interactive/index.js +0 -2
- package/dist/interactive/interactive-manager.d.ts +0 -108
- package/dist/interactive/interactive-stream-hook.d.ts +0 -68
- package/dist/middleware/next/middleware.d.ts +0 -59
- package/dist/middleware/next/storage.d.ts +0 -14
- package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
- package/dist/middleware/shared/headers.d.ts +0 -14
- package/dist/middleware/shared/routes.d.ts +0 -30
- package/dist/middleware/shared/storage.d.ts +0 -29
- package/dist/packem_shared/InteractiveManager-CowYA3Hx.js +0 -178
- package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
- package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
- package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
- package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
- package/dist/pail.browser.d.ts +0 -412
- package/dist/pail.server.d.ts +0 -233
- package/dist/processor/caller/get-caller-filename.d.ts +0 -23
- package/dist/progress-bar.d.ts +0 -145
- package/dist/progress-bar.js +0 -459
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
- package/dist/reporter/http/utils/compression.d.ts +0 -7
- package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
- package/dist/reporter/http/utils/retry.d.ts +0 -27
- package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
- package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
- package/dist/reporter/json/json-reporter.server.d.ts +0 -50
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
- package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
- package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
- package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
- package/dist/reporter/utils/format-label.d.ts +0 -3
- package/dist/spinner.d.ts +0 -220
- package/dist/spinner.js +0 -2183
- package/dist/types.d.ts +0 -241
- package/dist/utils/ansi-escapes.d.ts +0 -4
- package/dist/utils/arrayify.d.ts +0 -2
- package/dist/utils/get-longest-badge.d.ts +0 -4
- package/dist/utils/get-longest-label.d.ts +0 -4
- package/dist/utils/merge-types.d.ts +0 -4
- package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
- package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
- package/dist/utils/write-stream.d.ts +0 -2
|
@@ -1,40 +1,432 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import '@visulima/colorize';
|
|
2
|
+
import '@visulima/interactive-manager';
|
|
3
|
+
import { stringify } from 'safe-stable-stringify';
|
|
4
|
+
/**
|
|
5
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
6
|
+
|
|
7
|
+
@category Type
|
|
8
|
+
*/
|
|
9
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
10
|
+
/**
|
|
11
|
+
Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
12
|
+
|
|
13
|
+
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
|
14
|
+
|
|
15
|
+
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
|
16
|
+
|
|
17
|
+
@example
|
|
18
|
+
```
|
|
19
|
+
import type {LiteralUnion} from 'type-fest';
|
|
20
|
+
|
|
21
|
+
// Before
|
|
22
|
+
|
|
23
|
+
type Pet = 'dog' | 'cat' | string;
|
|
24
|
+
|
|
25
|
+
const petWithoutAutocomplete: Pet = '';
|
|
26
|
+
// Start typing in your TypeScript-enabled IDE.
|
|
27
|
+
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
28
|
+
|
|
29
|
+
// After
|
|
30
|
+
|
|
31
|
+
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
32
|
+
|
|
33
|
+
const petWithAutoComplete: Pet2 = '';
|
|
34
|
+
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
@category Type
|
|
38
|
+
*/
|
|
39
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
40
|
+
/**
|
|
41
|
+
* Global namespace for extending Pail's metadata interface.
|
|
42
|
+
*
|
|
43
|
+
* This global declaration allows other packages and applications to extend
|
|
44
|
+
* the Meta interface with custom properties by declaring additional properties
|
|
45
|
+
* in the VisulimaPail.CustomMeta interface.
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* declare global {
|
|
49
|
+
* namespace VisulimaPail {
|
|
50
|
+
* interface CustomMeta<L> {
|
|
51
|
+
* userId?: string;
|
|
52
|
+
* requestId?: string;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare global {
|
|
59
|
+
namespace VisulimaPail {
|
|
60
|
+
interface CustomMeta<L> {}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Metadata object containing all information about a log entry.
|
|
65
|
+
*
|
|
66
|
+
* This interface defines the structure of metadata that is passed to reporters
|
|
67
|
+
* and processors. It contains all the contextual information about a log message
|
|
68
|
+
* including the message itself, timing information, error details, and more.
|
|
69
|
+
* @template L - The log level type
|
|
70
|
+
*/
|
|
71
|
+
interface Meta<L> extends VisulimaPail.CustomMeta<L> {
|
|
72
|
+
badge: string | undefined;
|
|
73
|
+
context: any[] | undefined;
|
|
74
|
+
date: Date | string;
|
|
75
|
+
error: Error | undefined;
|
|
76
|
+
groups: string[];
|
|
77
|
+
label: string | undefined;
|
|
78
|
+
message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
|
|
79
|
+
prefix: string | undefined;
|
|
80
|
+
repeated?: number;
|
|
81
|
+
scope: string[] | undefined;
|
|
82
|
+
suffix: string | undefined;
|
|
83
|
+
traceError: Error | undefined;
|
|
84
|
+
type: {
|
|
85
|
+
level: ExtendedRfc5424LogLevels | L;
|
|
86
|
+
name: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Extended RFC 5424 Log Levels.
|
|
91
|
+
*
|
|
92
|
+
* Standard syslog severity levels as defined in RFC 5424, plus additional
|
|
93
|
+
* levels commonly used in modern applications. Each level has a numeric
|
|
94
|
+
* priority where lower numbers indicate higher severity.
|
|
95
|
+
* @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
|
|
96
|
+
*/
|
|
97
|
+
type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
|
|
98
|
+
/**
|
|
99
|
+
* Read-only Metadata.
|
|
100
|
+
*
|
|
101
|
+
* Immutable version of the Meta interface for use in reporters.
|
|
102
|
+
* @template L - The log level type
|
|
103
|
+
*/
|
|
104
|
+
type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
|
|
105
|
+
/**
|
|
106
|
+
* Reporter Interface.
|
|
107
|
+
*
|
|
108
|
+
* Base interface for all reporters. Reporters are responsible for
|
|
109
|
+
* outputting log messages to various destinations (console, files, etc.).
|
|
110
|
+
* @template L - The log level type
|
|
111
|
+
*/
|
|
112
|
+
interface Reporter<L extends string> {
|
|
113
|
+
log: (meta: ReadonlyMeta<L>) => void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Stringify-Aware Reporter Interface.
|
|
117
|
+
*
|
|
118
|
+
* Extends Reporter with the ability to receive a custom stringify function.
|
|
119
|
+
* Useful for reporters that need to serialize complex objects.
|
|
120
|
+
* @template L - The log level type
|
|
121
|
+
*/
|
|
122
|
+
interface StringifyAwareReporter<L extends string> extends Reporter<L> {
|
|
123
|
+
/** Set the stringify function for object serialization */
|
|
124
|
+
setStringify: (stringify: any) => void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Options for configuring JSON reporters.
|
|
128
|
+
*/
|
|
129
|
+
type AbstractJsonReporterOptions = {
|
|
130
|
+
/** Error serialization options */
|
|
131
|
+
error: Partial<{
|
|
132
|
+
/** Properties to exclude from error serialization */
|
|
133
|
+
exclude?: string[];
|
|
134
|
+
/** Maximum depth for error object serialization */
|
|
135
|
+
maxDepth?: number;
|
|
136
|
+
/** Whether to use toJSON methods during serialization */
|
|
137
|
+
useToJSON?: boolean;
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Abstract JSON Reporter.
|
|
142
|
+
*
|
|
143
|
+
* Base class for JSON-based reporters that provides common functionality
|
|
144
|
+
* for serializing log metadata to JSON format. Handles error serialization,
|
|
145
|
+
* context processing, and provides a template method for actual output.
|
|
146
|
+
* @template L - The log level type
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* class CustomJsonReporter extends AbstractJsonReporter {
|
|
150
|
+
* protected _log(message: string): void {
|
|
151
|
+
* console.log(message);
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare abstract class AbstractJsonReporter<L extends string = string> implements StringifyAwareReporter<L> {
|
|
157
|
+
/** Custom stringify function for object serialization */
|
|
158
|
+
protected stringify: typeof stringify | undefined;
|
|
159
|
+
/** Error serialization options */
|
|
160
|
+
protected errorOptions: AbstractJsonReporterOptions["error"];
|
|
161
|
+
/**
|
|
162
|
+
* Creates a new AbstractJsonReporter instance.
|
|
163
|
+
* @param options Configuration options for JSON formatting and error handling
|
|
164
|
+
*/
|
|
165
|
+
constructor(options?: Partial<AbstractJsonReporterOptions>);
|
|
166
|
+
/**
|
|
167
|
+
* Sets a custom stringify function for object serialization.
|
|
168
|
+
* @param function_ The stringify function to use for serialization
|
|
169
|
+
*/
|
|
170
|
+
setStringify(function_: typeof stringify): void;
|
|
171
|
+
log(meta: ReadonlyMeta<L>): void;
|
|
172
|
+
/**
|
|
173
|
+
* Template method for outputting the JSON log message.
|
|
174
|
+
*
|
|
175
|
+
* Subclasses must implement this method to define how the JSON message
|
|
176
|
+
* is actually written (to console, file, network, etc.).
|
|
177
|
+
* @param message The JSON-formatted log message
|
|
178
|
+
* @param logLevel The log level of the message
|
|
179
|
+
* @protected
|
|
180
|
+
* @abstract
|
|
181
|
+
*/
|
|
182
|
+
protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Configuration options for the HTTP reporter.
|
|
186
|
+
*/
|
|
187
|
+
type AbstractHttpReporterOptions = AbstractJsonReporterOptions & {
|
|
188
|
+
/**
|
|
189
|
+
* Content type for batch log requests. User-specified headers take precedence.
|
|
190
|
+
* @default "application/json"
|
|
191
|
+
*/
|
|
192
|
+
batchContentType?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Field name to wrap batch entries in when batchMode is "field" (e.g., "batch" for Logflare)
|
|
195
|
+
* @default undefined
|
|
196
|
+
*/
|
|
197
|
+
batchFieldName?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Batch mode for sending multiple log entries
|
|
200
|
+
* - "delimiter": Join entries with a delimiter (default)
|
|
201
|
+
* - "field": Wrap entries in an object with a field name
|
|
202
|
+
* - "array": Send entries as a plain JSON array
|
|
203
|
+
* @default "delimiter"
|
|
204
|
+
*/
|
|
205
|
+
batchMode?: "delimiter" | "field" | "array";
|
|
206
|
+
/**
|
|
207
|
+
* Delimiter to use between log entries in batch mode
|
|
208
|
+
* @default "\n"
|
|
209
|
+
*/
|
|
210
|
+
batchSendDelimiter?: string;
|
|
211
|
+
/**
|
|
212
|
+
* Timeout in milliseconds for sending batches regardless of size
|
|
213
|
+
* @default 5000
|
|
214
|
+
*/
|
|
215
|
+
batchSendTimeout?: number;
|
|
216
|
+
/**
|
|
217
|
+
* Number of log entries to batch before sending
|
|
218
|
+
* @default 100
|
|
219
|
+
*/
|
|
220
|
+
batchSize?: number;
|
|
221
|
+
/**
|
|
222
|
+
* Whether to use gzip compression
|
|
223
|
+
* @default false
|
|
224
|
+
*/
|
|
225
|
+
compression?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Content type for single log requests. User-specified headers take precedence.
|
|
228
|
+
* @default "application/json"
|
|
229
|
+
*/
|
|
230
|
+
contentType?: string;
|
|
231
|
+
/**
|
|
232
|
+
* Whether to enable Edge Runtime compatibility mode
|
|
233
|
+
* When enabled, TextEncoder and compression are disabled
|
|
234
|
+
* @default false
|
|
235
|
+
*/
|
|
236
|
+
edgeCompat?: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Whether to enable batch sending
|
|
239
|
+
* @default true
|
|
240
|
+
*/
|
|
241
|
+
enableBatchSend?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Headers to include in the request. Can be an object or a function that returns headers.
|
|
244
|
+
*/
|
|
245
|
+
headers?: Record<string, string> | (() => Record<string, string>);
|
|
246
|
+
/**
|
|
247
|
+
* Maximum size of a single log entry in bytes
|
|
248
|
+
* @default 1048576 (1MB)
|
|
249
|
+
*/
|
|
250
|
+
maxLogSize?: number;
|
|
251
|
+
/**
|
|
252
|
+
* Maximum size of the payload (uncompressed) in bytes
|
|
253
|
+
* @default 5242880 (5MB)
|
|
254
|
+
*/
|
|
255
|
+
maxPayloadSize?: number;
|
|
256
|
+
/**
|
|
257
|
+
* Number of retry attempts before giving up
|
|
258
|
+
* @default 3
|
|
259
|
+
*/
|
|
260
|
+
maxRetries?: number;
|
|
261
|
+
/**
|
|
262
|
+
* HTTP method to use for requests
|
|
263
|
+
* @default "POST"
|
|
264
|
+
*/
|
|
265
|
+
method?: string;
|
|
266
|
+
/**
|
|
267
|
+
* Optional callback for debugging log entries before they are sent
|
|
268
|
+
*/
|
|
269
|
+
onDebug?: (entry: Record<string, unknown>) => void;
|
|
270
|
+
/**
|
|
271
|
+
* Optional callback for debugging HTTP requests and responses
|
|
272
|
+
*/
|
|
273
|
+
onDebugRequestResponse?: (requestResponse: {
|
|
274
|
+
req: {
|
|
275
|
+
body: string | Uint8Array;
|
|
276
|
+
headers: Record<string, string>;
|
|
277
|
+
method: string;
|
|
278
|
+
url: string;
|
|
279
|
+
};
|
|
280
|
+
res: {
|
|
281
|
+
body: string;
|
|
282
|
+
headers: Record<string, string>;
|
|
283
|
+
status: number;
|
|
284
|
+
statusText: string;
|
|
285
|
+
};
|
|
286
|
+
}) => void;
|
|
287
|
+
/**
|
|
288
|
+
* Optional callback for error handling
|
|
289
|
+
*/
|
|
290
|
+
onError?: (error: Error) => void;
|
|
291
|
+
/**
|
|
292
|
+
* Function to transform log data into the payload format.
|
|
293
|
+
* By default, uses the JSON stringified log entry.
|
|
294
|
+
*/
|
|
295
|
+
payloadTemplate?: (data: {
|
|
296
|
+
data?: Record<string, unknown>;
|
|
297
|
+
logLevel: string;
|
|
298
|
+
message: string;
|
|
299
|
+
}) => string;
|
|
300
|
+
/**
|
|
301
|
+
* Whether to respect rate limiting by waiting when a 429 response is received
|
|
302
|
+
* @default true
|
|
303
|
+
*/
|
|
304
|
+
respectRateLimit?: boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Base delay between retries in milliseconds
|
|
307
|
+
* @default 1000
|
|
308
|
+
*/
|
|
309
|
+
retryDelay?: number;
|
|
310
|
+
/**
|
|
311
|
+
* The URL to send logs to
|
|
312
|
+
*/
|
|
313
|
+
url: string;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* Abstract HTTP Reporter.
|
|
317
|
+
*
|
|
318
|
+
* Base class for HTTP-based reporters that sends logs to HTTP endpoints.
|
|
319
|
+
* Supports batching, compression, retries, and rate limiting.
|
|
320
|
+
* @template L - The log level type
|
|
321
|
+
*/
|
|
322
|
+
declare abstract class AbstractHttpReporter<L extends string = string> extends AbstractJsonReporter<L> implements StringifyAwareReporter<L> {
|
|
323
|
+
protected url: string;
|
|
324
|
+
protected method: string;
|
|
325
|
+
protected headers: Record<string, string> | (() => Record<string, string>);
|
|
326
|
+
protected contentType: string;
|
|
327
|
+
protected batchContentType: string;
|
|
328
|
+
protected onError?: (error: Error) => void;
|
|
329
|
+
protected onDebug?: (entry: Record<string, unknown>) => void;
|
|
330
|
+
protected onDebugRequestResponse?: (requestResponse: {
|
|
331
|
+
req: {
|
|
332
|
+
body: string | Uint8Array;
|
|
333
|
+
headers: Record<string, string>;
|
|
334
|
+
method: string;
|
|
335
|
+
url: string;
|
|
336
|
+
};
|
|
337
|
+
res: {
|
|
338
|
+
body: string;
|
|
339
|
+
headers: Record<string, string>;
|
|
340
|
+
status: number;
|
|
341
|
+
statusText: string;
|
|
342
|
+
};
|
|
343
|
+
}) => void;
|
|
344
|
+
protected payloadTemplate: (data: {
|
|
345
|
+
data?: Record<string, unknown>;
|
|
346
|
+
logLevel: string;
|
|
347
|
+
message: string;
|
|
348
|
+
}) => string;
|
|
349
|
+
protected compression: boolean;
|
|
350
|
+
protected maxRetries: number;
|
|
351
|
+
protected retryDelay: number;
|
|
352
|
+
protected respectRateLimit: boolean;
|
|
353
|
+
protected enableBatchSend: boolean;
|
|
354
|
+
protected batchSize: number;
|
|
355
|
+
protected batchSendTimeout: number;
|
|
356
|
+
protected batchSendDelimiter: string;
|
|
357
|
+
protected batchMode: "delimiter" | "field" | "array";
|
|
358
|
+
protected batchFieldName?: string;
|
|
359
|
+
protected maxLogSize: number;
|
|
360
|
+
protected maxPayloadSize: number;
|
|
361
|
+
protected edgeCompat: boolean;
|
|
362
|
+
protected batchQueue: string[];
|
|
363
|
+
protected batchTimeout?: ReturnType<typeof setTimeout>;
|
|
364
|
+
protected isProcessingBatch: boolean;
|
|
365
|
+
protected currentBatchSize: number;
|
|
366
|
+
/**
|
|
367
|
+
* Creates a new instance of AbstractHttpReporter.
|
|
368
|
+
* @param config Configuration options for the reporter
|
|
369
|
+
*/
|
|
370
|
+
constructor(config: AbstractHttpReporterOptions);
|
|
371
|
+
/**
|
|
372
|
+
* Processes and ships log entries to the HTTP endpoint.
|
|
373
|
+
* @param message The JSON-formatted log message
|
|
374
|
+
* @param logLevel The log level of the message
|
|
375
|
+
* @protected
|
|
376
|
+
*/
|
|
377
|
+
protected override _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
|
|
378
|
+
/**
|
|
379
|
+
* Adds a payload to the batch queue and triggers sending if conditions are met.
|
|
380
|
+
*/
|
|
381
|
+
protected addToBatch(payload: string, logEntrySize: number): void;
|
|
382
|
+
/**
|
|
383
|
+
* Processes the current batch and sends it to the HTTP endpoint.
|
|
384
|
+
*/
|
|
385
|
+
protected processBatch(): Promise<void>;
|
|
386
|
+
/**
|
|
387
|
+
* Sends a batch of payloads to the HTTP endpoint.
|
|
388
|
+
*/
|
|
389
|
+
protected sendBatch(batch: string[]): Promise<void>;
|
|
390
|
+
/**
|
|
391
|
+
* Sends a single payload to the HTTP endpoint.
|
|
392
|
+
*/
|
|
393
|
+
protected sendPayload(payload: string, contentType?: string): Promise<void>;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* HTTP Reporter for Edge Runtime environments.
|
|
397
|
+
*
|
|
398
|
+
* A reporter optimized for Edge Runtime environments (Next.js Edge, Cloudflare Workers, etc.)
|
|
399
|
+
* that sends logs to HTTP endpoints. Edge compatibility mode is enabled by default.
|
|
400
|
+
* Supports batching, retries, and rate limiting. Compression is disabled for Edge compatibility.
|
|
401
|
+
* @template L - The log level type
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* import { createPail } from "@visulima/pail";
|
|
405
|
+
* import { HttpReporterEdgeLight } from "@visulima/pail/reporter/http/edge-light";
|
|
406
|
+
*
|
|
407
|
+
* const logger = createPail({
|
|
408
|
+
* reporters: [
|
|
409
|
+
* new HttpReporterEdgeLight({
|
|
410
|
+
* url: "https://api.example.com/logs",
|
|
411
|
+
* method: "POST",
|
|
412
|
+
* headers: {
|
|
413
|
+
* "Authorization": "Bearer token"
|
|
414
|
+
* },
|
|
415
|
+
* enableBatchSend: true,
|
|
416
|
+
* batchSize: 50
|
|
417
|
+
* })
|
|
418
|
+
* ]
|
|
419
|
+
* });
|
|
420
|
+
*
|
|
421
|
+
* logger.info("Edge function started");
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
32
424
|
declare class HttpReporterEdgeLight<L extends string = string> extends AbstractHttpReporter<L> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
425
|
+
/**
|
|
426
|
+
* Creates a new HTTP Reporter Edge Light instance.
|
|
427
|
+
* Edge compatibility mode is automatically enabled.
|
|
428
|
+
* @param options Configuration options for HTTP reporting
|
|
429
|
+
*/
|
|
430
|
+
constructor(options: Omit<AbstractHttpReporterOptions, "edgeCompat">);
|
|
39
431
|
}
|
|
40
|
-
export default
|
|
432
|
+
export { HttpReporterEdgeLight as default };
|
|
@@ -284,11 +284,7 @@ class AbstractJsonReporter {
|
|
|
284
284
|
if (file) {
|
|
285
285
|
rest.file = `${file.name ?? ""}:${String(file.line)}${file.column ? `:${String(file.column)}` : ""}`;
|
|
286
286
|
}
|
|
287
|
-
|
|
288
|
-
rest.message = void 0;
|
|
289
|
-
} else {
|
|
290
|
-
rest.message = message;
|
|
291
|
-
}
|
|
287
|
+
rest.message = message === EMPTY_SYMBOL ? void 0 : message;
|
|
292
288
|
if (error) {
|
|
293
289
|
rest.error = serialize(error, this.errorOptions);
|
|
294
290
|
}
|
|
@@ -1,3 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { stringify } from 'safe-stable-stringify';
|
|
2
|
+
import { LiteralUnion } from 'type-fest';
|
|
3
|
+
import { R as ReadonlyMeta, E as ExtendedRfc5424LogLevels, S as StringifyAwareReporter } from "../../packem_shared/types.d-C51XNfQz.js";
|
|
4
|
+
import '@visulima/colorize';
|
|
5
|
+
import '@visulima/interactive-manager';
|
|
6
|
+
/**
|
|
7
|
+
* Options for configuring JSON reporters.
|
|
8
|
+
*/
|
|
9
|
+
type AbstractJsonReporterOptions = {
|
|
10
|
+
/** Error serialization options */
|
|
11
|
+
error: Partial<{
|
|
12
|
+
/** Properties to exclude from error serialization */
|
|
13
|
+
exclude?: string[];
|
|
14
|
+
/** Maximum depth for error object serialization */
|
|
15
|
+
maxDepth?: number;
|
|
16
|
+
/** Whether to use toJSON methods during serialization */
|
|
17
|
+
useToJSON?: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Abstract JSON Reporter.
|
|
22
|
+
*
|
|
23
|
+
* Base class for JSON-based reporters that provides common functionality
|
|
24
|
+
* for serializing log metadata to JSON format. Handles error serialization,
|
|
25
|
+
* context processing, and provides a template method for actual output.
|
|
26
|
+
* @template L - The log level type
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* class CustomJsonReporter extends AbstractJsonReporter {
|
|
30
|
+
* protected _log(message: string): void {
|
|
31
|
+
* console.log(message);
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare abstract class AbstractJsonReporter<L extends string = string> implements StringifyAwareReporter<L> {
|
|
37
|
+
/** Custom stringify function for object serialization */
|
|
38
|
+
protected stringify: typeof stringify | undefined;
|
|
39
|
+
/** Error serialization options */
|
|
40
|
+
protected errorOptions: AbstractJsonReporterOptions["error"];
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new AbstractJsonReporter instance.
|
|
43
|
+
* @param options Configuration options for JSON formatting and error handling
|
|
44
|
+
*/
|
|
45
|
+
constructor(options?: Partial<AbstractJsonReporterOptions>);
|
|
46
|
+
/**
|
|
47
|
+
* Sets a custom stringify function for object serialization.
|
|
48
|
+
* @param function_ The stringify function to use for serialization
|
|
49
|
+
*/
|
|
50
|
+
setStringify(function_: typeof stringify): void;
|
|
51
|
+
log(meta: ReadonlyMeta<L>): void;
|
|
52
|
+
/**
|
|
53
|
+
* Template method for outputting the JSON log message.
|
|
54
|
+
*
|
|
55
|
+
* Subclasses must implement this method to define how the JSON message
|
|
56
|
+
* is actually written (to console, file, network, etc.).
|
|
57
|
+
* @param message The JSON-formatted log message
|
|
58
|
+
* @param logLevel The log level of the message
|
|
59
|
+
* @protected
|
|
60
|
+
* @abstract
|
|
61
|
+
*/
|
|
62
|
+
protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Browser JSON Reporter.
|
|
66
|
+
*
|
|
67
|
+
* A JSON reporter for browser environments that outputs structured log data
|
|
68
|
+
* to the browser console. Uses appropriate console methods based on log level.
|
|
69
|
+
* @template L - The log level type
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { createPail } from "@visulima/pail";
|
|
73
|
+
*
|
|
74
|
+
* const logger = createPail({
|
|
75
|
+
* reporters: [new JsonReporter()]
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* logger.info("Application started", { version: "1.0.0" });
|
|
79
|
+
* // Outputs: {"level":"info","message":"Application started","context":[{"version":"1.0.0"}],...}
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> {
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new Browser JSON Reporter instance.
|
|
85
|
+
* @param options Configuration options for JSON formatting
|
|
86
|
+
*/
|
|
87
|
+
constructor(options?: Partial<AbstractJsonReporterOptions>);
|
|
88
|
+
/**
|
|
89
|
+
* Outputs the JSON message to the browser console.
|
|
90
|
+
*
|
|
91
|
+
* Uses the appropriate console method based on the log level
|
|
92
|
+
* (console.log, console.error, console.warn, etc.).
|
|
93
|
+
* @param message The JSON-formatted log message
|
|
94
|
+
* @param logLevel The log level determining which console method to use
|
|
95
|
+
* @protected
|
|
96
|
+
*/
|
|
97
|
+
protected override _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
|
|
98
|
+
}
|
|
99
|
+
export { AbstractJsonReporter, type AbstractJsonReporterOptions, JsonReporter };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-
|
|
2
|
-
export { default as JsonReporter } from '../../packem_shared/JsonReporter-
|
|
1
|
+
export { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-BO8Calb4.js';
|
|
2
|
+
export { default as JsonReporter } from '../../packem_shared/JsonReporter-CCmj7oYL.js';
|
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-BAgznjyU.js";
|
|
2
|
+
import { E as ExtendedRfc5424LogLevels, L as LiteralUnion, a as StreamAwareReporter } from "../../packem_shared/types.d-BeLumqgD.js";
|
|
3
|
+
import 'safe-stable-stringify';
|
|
4
|
+
import '@visulima/colorize';
|
|
5
|
+
import '@visulima/interactive-manager';
|
|
6
|
+
/**
|
|
7
|
+
* Server JSON Reporter.
|
|
8
|
+
*
|
|
9
|
+
* A JSON reporter for Node.js server environments that outputs structured log data
|
|
10
|
+
* to stdout/stderr streams. Routes error-level logs to stderr and others to stdout.
|
|
11
|
+
* @template L - The log level type
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createPail } from "@visulima/pail";
|
|
15
|
+
*
|
|
16
|
+
* const logger = createPail({
|
|
17
|
+
* reporters: [new JsonReporter()]
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* logger.info("Server started", { port: 3000 });
|
|
21
|
+
* logger.error("Database connection failed", error);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> implements StreamAwareReporter<L> {
|
|
25
|
+
#private;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new Server JSON Reporter instance.
|
|
28
|
+
* @param options Configuration options for JSON formatting
|
|
29
|
+
*/
|
|
30
|
+
constructor(options?: Partial<AbstractJsonReporterOptions>);
|
|
31
|
+
/**
|
|
32
|
+
* Sets the stdout stream for the reporter.
|
|
33
|
+
* @param stdout_ The writable stream to use for stdout output
|
|
34
|
+
*/
|
|
35
|
+
setStdout(stdout_: NodeJS.WriteStream): void;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the stderr stream for the reporter.
|
|
38
|
+
* @param stderr_ The writable stream to use for stderr output
|
|
39
|
+
*/
|
|
40
|
+
setStderr(stderr_: NodeJS.WriteStream): void;
|
|
41
|
+
/**
|
|
42
|
+
* Outputs the JSON message to the appropriate stream.
|
|
43
|
+
*
|
|
44
|
+
* Routes error and warning level messages to stderr, others to stdout.
|
|
45
|
+
* @param message The JSON-formatted log message
|
|
46
|
+
* @param logLevel The log level determining which stream to use
|
|
47
|
+
* @protected
|
|
48
|
+
*/
|
|
49
|
+
protected override _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
|
|
50
|
+
}
|
|
51
|
+
export { AbstractJsonReporter, type AbstractJsonReporterOptions, JsonReporter };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-
|
|
2
|
-
export { default as JsonReporter } from '../../packem_shared/JsonReporter-
|
|
1
|
+
export { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-nOj0Ft1F.js';
|
|
2
|
+
export { default as JsonReporter } from '../../packem_shared/JsonReporter-Ck2PIAEw.js';
|