@visulima/pail 4.0.0-alpha.11 → 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 +17 -0
- package/LICENSE.md +152 -894
- package/dist/error.d.ts +95 -96
- package/dist/index.browser.d.ts +557 -47
- package/dist/index.browser.js +1 -1
- package/dist/index.server.d.ts +722 -61
- package/dist/index.server.js +5 -4
- package/dist/middleware/elysia.d.ts +65 -63
- package/dist/middleware/express.d.ts +73 -71
- package/dist/middleware/fastify.d.ts +69 -67
- 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/{PrettyReporter-BtTr13Ha.js → PrettyReporter-CIbrmjUV.js} +1 -1
- package/dist/packem_shared/{PrettyReporter-BCvyNzXO.js → PrettyReporter-CNJEO9g7.js} +11 -8
- package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
- package/dist/packem_shared/{abstract-pretty-reporter-CXAKYCb8.js → abstract-pretty-reporter-CkqCt5hg.js} +4 -2
- 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/processor/caller/caller-processor.d.ts +49 -47
- package/dist/processor/environment-processor.d.ts +113 -113
- package/dist/processor/environment-processor.js +3 -10
- 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/http/abstract-http-reporter.d.ts +213 -211
- 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/json/index.browser.d.ts +99 -3
- package/dist/reporter/json/index.d.ts +51 -3
- 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/package.json +6 -7
- package/dist/constants.d.ts +0 -37
- 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/pail.browser.d.ts +0 -412
- package/dist/pail.server.d.ts +0 -158
- package/dist/processor/caller/get-caller-filename.d.ts +0 -23
- 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/types.d.ts +0 -241
- 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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { P as PailBrowserImpl } from "./wide-event.d-B-t8ZnhI.js";
|
|
2
|
+
import { D as DefaultLogTypes, e as LoggerFunction } from "./types.d-BeLumqgD.js";
|
|
3
|
+
/**
|
|
4
|
+
* Route configuration for a specific path pattern.
|
|
5
|
+
*/
|
|
6
|
+
interface RouteConfig {
|
|
7
|
+
/** Override the service name for requests matching this route. */
|
|
8
|
+
service?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A pail instance with dynamically generated log methods.
|
|
12
|
+
*/
|
|
13
|
+
type PailLike<T extends string = string> = PailBrowserImpl<T> & Record<DefaultLogTypes | T, LoggerFunction>;
|
|
14
|
+
/**
|
|
15
|
+
* Base options shared by all framework middleware adapters.
|
|
16
|
+
* @template T - Custom logger type names from the pail instance
|
|
17
|
+
*/
|
|
18
|
+
interface PailMiddlewareOptions<T extends string = string> {
|
|
19
|
+
/**
|
|
20
|
+
* Glob patterns for paths to exclude from logging.
|
|
21
|
+
* Exclusions take precedence over inclusions.
|
|
22
|
+
* @example ["/health", "/api/_internal/**"]
|
|
23
|
+
*/
|
|
24
|
+
exclude?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Glob patterns for paths to include in logging.
|
|
27
|
+
* If not set, all non-excluded paths are logged.
|
|
28
|
+
* @example ["/api/**"]
|
|
29
|
+
*/
|
|
30
|
+
include?: string[];
|
|
31
|
+
/**
|
|
32
|
+
* The pail logger instance to use for wide event emission.
|
|
33
|
+
*/
|
|
34
|
+
pail: PailLike<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Route-specific configuration. Maps glob patterns to config.
|
|
37
|
+
* First matching route wins.
|
|
38
|
+
* @example { "/api/auth/**": { service: "auth-service" } }
|
|
39
|
+
*/
|
|
40
|
+
routes?: Record<string, RouteConfig>;
|
|
41
|
+
/**
|
|
42
|
+
* Default service name for all wide events.
|
|
43
|
+
* Can be overridden per-route via `routes`.
|
|
44
|
+
*/
|
|
45
|
+
service?: string;
|
|
46
|
+
}
|
|
47
|
+
export { PailMiddlewareOptions as P };
|
|
@@ -330,7 +330,7 @@ const parseCss = (cssString) => {
|
|
|
330
330
|
}
|
|
331
331
|
return css;
|
|
332
332
|
};
|
|
333
|
-
const cssToAnsi = (css, previousCss
|
|
333
|
+
const cssToAnsi = (css, previousCss) => {
|
|
334
334
|
previousCss = previousCss ?? getDefaultCss();
|
|
335
335
|
let ansi = "";
|
|
336
336
|
if (!colorEquals(css.backgroundColor, previousCss.backgroundColor)) {
|
|
@@ -507,7 +507,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
|
|
|
507
507
|
let a = 1 - offset;
|
|
508
508
|
let lastPosition = -1;
|
|
509
509
|
let usedStyle = false;
|
|
510
|
-
let previousCss
|
|
510
|
+
let previousCss;
|
|
511
511
|
for (let index = 0; index < fmt.length; ) {
|
|
512
512
|
if (fmt.codePointAt(index) === CHAR_PERCENT && index + 1 < fmt.length) {
|
|
513
513
|
lastPosition = lastPosition > -1 ? lastPosition : 0;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { AnsiColors } from '@visulima/colorize';
|
|
2
|
+
import { InteractiveManager } from '@visulima/interactive-manager';
|
|
3
|
+
/**
|
|
4
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
5
|
+
|
|
6
|
+
@category Type
|
|
7
|
+
*/
|
|
8
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
9
|
+
/**
|
|
10
|
+
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.
|
|
11
|
+
|
|
12
|
+
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.
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
@example
|
|
17
|
+
```
|
|
18
|
+
import type {LiteralUnion} from 'type-fest';
|
|
19
|
+
|
|
20
|
+
// Before
|
|
21
|
+
|
|
22
|
+
type Pet = 'dog' | 'cat' | string;
|
|
23
|
+
|
|
24
|
+
const petWithoutAutocomplete: Pet = '';
|
|
25
|
+
// Start typing in your TypeScript-enabled IDE.
|
|
26
|
+
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
27
|
+
|
|
28
|
+
// After
|
|
29
|
+
|
|
30
|
+
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
31
|
+
|
|
32
|
+
const petWithAutoComplete: Pet2 = '';
|
|
33
|
+
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
@category Type
|
|
37
|
+
*/
|
|
38
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
39
|
+
/**
|
|
40
|
+
* Global namespace for extending Pail's metadata interface.
|
|
41
|
+
*
|
|
42
|
+
* This global declaration allows other packages and applications to extend
|
|
43
|
+
* the Meta interface with custom properties by declaring additional properties
|
|
44
|
+
* in the VisulimaPail.CustomMeta interface.
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* declare global {
|
|
48
|
+
* namespace VisulimaPail {
|
|
49
|
+
* interface CustomMeta<L> {
|
|
50
|
+
* userId?: string;
|
|
51
|
+
* requestId?: string;
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare global {
|
|
58
|
+
namespace VisulimaPail {
|
|
59
|
+
interface CustomMeta<L> {}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Metadata object containing all information about a log entry.
|
|
64
|
+
*
|
|
65
|
+
* This interface defines the structure of metadata that is passed to reporters
|
|
66
|
+
* and processors. It contains all the contextual information about a log message
|
|
67
|
+
* including the message itself, timing information, error details, and more.
|
|
68
|
+
* @template L - The log level type
|
|
69
|
+
*/
|
|
70
|
+
interface Meta<L> extends VisulimaPail.CustomMeta<L> {
|
|
71
|
+
badge: string | undefined;
|
|
72
|
+
context: any[] | undefined;
|
|
73
|
+
date: Date | string;
|
|
74
|
+
error: Error | undefined;
|
|
75
|
+
groups: string[];
|
|
76
|
+
label: string | undefined;
|
|
77
|
+
message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
|
|
78
|
+
prefix: string | undefined;
|
|
79
|
+
repeated?: number;
|
|
80
|
+
scope: string[] | undefined;
|
|
81
|
+
suffix: string | undefined;
|
|
82
|
+
traceError: Error | undefined;
|
|
83
|
+
type: {
|
|
84
|
+
level: ExtendedRfc5424LogLevels | L;
|
|
85
|
+
name: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Extended RFC 5424 Log Levels.
|
|
90
|
+
*
|
|
91
|
+
* Standard syslog severity levels as defined in RFC 5424, plus additional
|
|
92
|
+
* levels commonly used in modern applications. Each level has a numeric
|
|
93
|
+
* priority where lower numbers indicate higher severity.
|
|
94
|
+
* @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
|
|
95
|
+
*/
|
|
96
|
+
type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
|
|
97
|
+
/**
|
|
98
|
+
* Default Log Types.
|
|
99
|
+
*
|
|
100
|
+
* Predefined semantic log types that provide meaningful categorization
|
|
101
|
+
* for different kinds of log messages. Each type has associated styling
|
|
102
|
+
* and log level configuration.
|
|
103
|
+
*/
|
|
104
|
+
type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "warning" | "watch";
|
|
105
|
+
/**
|
|
106
|
+
* Logger Function Type.
|
|
107
|
+
*
|
|
108
|
+
* Represents a logging function that can accept either a structured Message object
|
|
109
|
+
* or multiple arguments in the traditional console.log style.
|
|
110
|
+
*/
|
|
111
|
+
interface LoggerFunction {
|
|
112
|
+
(message: Message): void;
|
|
113
|
+
(...message: any[]): void;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Logger Configuration.
|
|
117
|
+
*
|
|
118
|
+
* Configuration object that defines how a specific logger type should behave,
|
|
119
|
+
* including its visual appearance and log level.
|
|
120
|
+
* @template L - The log level type
|
|
121
|
+
*/
|
|
122
|
+
interface LoggerConfiguration<L extends string> {
|
|
123
|
+
badge?: string;
|
|
124
|
+
color?: AnsiColors;
|
|
125
|
+
label: string;
|
|
126
|
+
logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Logger Types Configuration.
|
|
130
|
+
*
|
|
131
|
+
* A record mapping logger type names to their configurations.
|
|
132
|
+
* @template T - Custom logger type names
|
|
133
|
+
* @template L - Log level types
|
|
134
|
+
*/
|
|
135
|
+
type LoggerTypesConfig<T extends string, L extends string> = Record<T, Partial<LoggerConfiguration<L>>>;
|
|
136
|
+
/**
|
|
137
|
+
* Read-only Metadata.
|
|
138
|
+
*
|
|
139
|
+
* Immutable version of the Meta interface for use in reporters.
|
|
140
|
+
* @template L - The log level type
|
|
141
|
+
*/
|
|
142
|
+
type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
|
|
143
|
+
/**
|
|
144
|
+
* Reporter Interface.
|
|
145
|
+
*
|
|
146
|
+
* Base interface for all reporters. Reporters are responsible for
|
|
147
|
+
* outputting log messages to various destinations (console, files, etc.).
|
|
148
|
+
* @template L - The log level type
|
|
149
|
+
*/
|
|
150
|
+
interface Reporter<L extends string> {
|
|
151
|
+
log: (meta: ReadonlyMeta<L>) => void;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Stream-Aware Reporter Interface.
|
|
155
|
+
*
|
|
156
|
+
* Extends Reporter with the ability to work with Node.js streams.
|
|
157
|
+
* Used for server-side reporters that need to write to stdout/stderr.
|
|
158
|
+
* @template L - The log level type
|
|
159
|
+
*/
|
|
160
|
+
interface StreamAwareReporter<L extends string> extends Reporter<L> {
|
|
161
|
+
/** Set the stderr stream for error output */
|
|
162
|
+
setStderr: (stderr: NodeJS.WriteStream) => void;
|
|
163
|
+
/** Set the stdout stream for standard output */
|
|
164
|
+
setStdout: (stdout: NodeJS.WriteStream) => void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Logger Types Aware Reporter Interface.
|
|
168
|
+
*
|
|
169
|
+
* Extends Reporter with the ability to receive logger type configurations.
|
|
170
|
+
* Allows reporters to customize their output based on logger types.
|
|
171
|
+
* @template T - Custom logger type names
|
|
172
|
+
* @template L - The log level type
|
|
173
|
+
*/
|
|
174
|
+
interface LoggerTypesAwareReporter<T extends string, L extends string> extends Reporter<L> {
|
|
175
|
+
/** Set the logger types configuration */
|
|
176
|
+
setLoggerTypes: (types: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>) => void;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Stringify-Aware Reporter Interface.
|
|
180
|
+
*
|
|
181
|
+
* Extends Reporter with the ability to receive a custom stringify function.
|
|
182
|
+
* Useful for reporters that need to serialize complex objects.
|
|
183
|
+
* @template L - The log level type
|
|
184
|
+
*/
|
|
185
|
+
interface StringifyAwareReporter<L extends string> extends Reporter<L> {
|
|
186
|
+
/** Set the stringify function for object serialization */
|
|
187
|
+
setStringify: (stringify: any) => void;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Interactive Stream Reporter Interface.
|
|
191
|
+
*
|
|
192
|
+
* Extends StreamAwareReporter with interactive capabilities for terminal UIs.
|
|
193
|
+
* Supports features like progress bars and dynamic updates.
|
|
194
|
+
* @template L - The log level type
|
|
195
|
+
*/
|
|
196
|
+
interface InteractiveStreamReporter<L extends string> extends StreamAwareReporter<L> {
|
|
197
|
+
/** Set the interactive manager for handling interactive output */
|
|
198
|
+
setInteractiveManager: (manager?: InteractiveManager) => void;
|
|
199
|
+
/** Enable or disable interactive mode */
|
|
200
|
+
setIsInteractive: (interactive: boolean) => void;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Processor Interface.
|
|
204
|
+
*
|
|
205
|
+
* Base interface for all processors. Processors can modify or enhance
|
|
206
|
+
* log metadata before it reaches reporters.
|
|
207
|
+
* @template L - The log level type
|
|
208
|
+
*/
|
|
209
|
+
interface Processor<L extends string> {
|
|
210
|
+
/** Process the log metadata */
|
|
211
|
+
process: (meta: Meta<L>) => Meta<L>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Stringify-Aware Processor Interface.
|
|
215
|
+
*
|
|
216
|
+
* Extends Processor with the ability to receive a custom stringify function.
|
|
217
|
+
* Useful for processors that need to serialize complex objects.
|
|
218
|
+
* @template L - The log level type
|
|
219
|
+
*/
|
|
220
|
+
interface StringifyAwareProcessor<L extends string> extends Processor<L> {
|
|
221
|
+
/** Set the stringify function for object serialization */
|
|
222
|
+
setStringify: (stringify: typeof JSON.stringify) => void;
|
|
223
|
+
}
|
|
224
|
+
interface ConstructorOptions<T extends string, L extends string> {
|
|
225
|
+
disabled?: boolean;
|
|
226
|
+
logLevel?: LiteralUnion<ExtendedRfc5424LogLevels, L>;
|
|
227
|
+
logLevels?: Partial<Record<ExtendedRfc5424LogLevels, number>> & Record<L, number>;
|
|
228
|
+
messages?: {
|
|
229
|
+
timerEnd?: string;
|
|
230
|
+
timerStart?: string;
|
|
231
|
+
};
|
|
232
|
+
processors?: Processor<L>[];
|
|
233
|
+
rawReporter?: Reporter<L>;
|
|
234
|
+
reporters?: Reporter<L>[];
|
|
235
|
+
scope?: string[] | string;
|
|
236
|
+
throttle?: number;
|
|
237
|
+
throttleMin?: number;
|
|
238
|
+
types?: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>;
|
|
239
|
+
}
|
|
240
|
+
type Message = {
|
|
241
|
+
context?: any[];
|
|
242
|
+
message: any;
|
|
243
|
+
prefix?: string;
|
|
244
|
+
suffix?: string;
|
|
245
|
+
};
|
|
246
|
+
export { ConstructorOptions as C, DefaultLogTypes as D, ExtendedRfc5424LogLevels as E, InteractiveStreamReporter as I, LiteralUnion as L, Meta as M, Processor as P, ReadonlyMeta as R, StringifyAwareReporter as S, StreamAwareReporter as a, StringifyAwareProcessor as b, LoggerTypesConfig as c, Reporter as d, LoggerFunction as e, LoggerTypesAwareReporter as f };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { AnsiColors } from '@visulima/colorize';
|
|
2
|
+
import '@visulima/interactive-manager';
|
|
3
|
+
import { LiteralUnion, Primitive } from 'type-fest';
|
|
4
|
+
/**
|
|
5
|
+
* Global namespace for extending Pail's metadata interface.
|
|
6
|
+
*
|
|
7
|
+
* This global declaration allows other packages and applications to extend
|
|
8
|
+
* the Meta interface with custom properties by declaring additional properties
|
|
9
|
+
* in the VisulimaPail.CustomMeta interface.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* declare global {
|
|
13
|
+
* namespace VisulimaPail {
|
|
14
|
+
* interface CustomMeta<L> {
|
|
15
|
+
* userId?: string;
|
|
16
|
+
* requestId?: string;
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare global {
|
|
23
|
+
namespace VisulimaPail {
|
|
24
|
+
interface CustomMeta<L> {}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Metadata object containing all information about a log entry.
|
|
29
|
+
*
|
|
30
|
+
* This interface defines the structure of metadata that is passed to reporters
|
|
31
|
+
* and processors. It contains all the contextual information about a log message
|
|
32
|
+
* including the message itself, timing information, error details, and more.
|
|
33
|
+
* @template L - The log level type
|
|
34
|
+
*/
|
|
35
|
+
interface Meta<L> extends VisulimaPail.CustomMeta<L> {
|
|
36
|
+
badge: string | undefined;
|
|
37
|
+
context: any[] | undefined;
|
|
38
|
+
date: Date | string;
|
|
39
|
+
error: Error | undefined;
|
|
40
|
+
groups: string[];
|
|
41
|
+
label: string | undefined;
|
|
42
|
+
message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
|
|
43
|
+
prefix: string | undefined;
|
|
44
|
+
repeated?: number;
|
|
45
|
+
scope: string[] | undefined;
|
|
46
|
+
suffix: string | undefined;
|
|
47
|
+
traceError: Error | undefined;
|
|
48
|
+
type: {
|
|
49
|
+
level: ExtendedRfc5424LogLevels | L;
|
|
50
|
+
name: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extended RFC 5424 Log Levels.
|
|
55
|
+
*
|
|
56
|
+
* Standard syslog severity levels as defined in RFC 5424, plus additional
|
|
57
|
+
* levels commonly used in modern applications. Each level has a numeric
|
|
58
|
+
* priority where lower numbers indicate higher severity.
|
|
59
|
+
* @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
|
|
60
|
+
*/
|
|
61
|
+
type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
|
|
62
|
+
/**
|
|
63
|
+
* Default Log Types.
|
|
64
|
+
*
|
|
65
|
+
* Predefined semantic log types that provide meaningful categorization
|
|
66
|
+
* for different kinds of log messages. Each type has associated styling
|
|
67
|
+
* and log level configuration.
|
|
68
|
+
*/
|
|
69
|
+
type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "warning" | "watch";
|
|
70
|
+
/**
|
|
71
|
+
* Logger Function Type.
|
|
72
|
+
*
|
|
73
|
+
* Represents a logging function that can accept either a structured Message object
|
|
74
|
+
* or multiple arguments in the traditional console.log style.
|
|
75
|
+
*/
|
|
76
|
+
interface LoggerFunction {
|
|
77
|
+
(message: Message): void;
|
|
78
|
+
(...message: any[]): void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Logger Configuration.
|
|
82
|
+
*
|
|
83
|
+
* Configuration object that defines how a specific logger type should behave,
|
|
84
|
+
* including its visual appearance and log level.
|
|
85
|
+
* @template L - The log level type
|
|
86
|
+
*/
|
|
87
|
+
interface LoggerConfiguration<L extends string> {
|
|
88
|
+
badge?: string;
|
|
89
|
+
color?: AnsiColors;
|
|
90
|
+
label: string;
|
|
91
|
+
logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Logger Types Configuration.
|
|
95
|
+
*
|
|
96
|
+
* A record mapping logger type names to their configurations.
|
|
97
|
+
* @template T - Custom logger type names
|
|
98
|
+
* @template L - Log level types
|
|
99
|
+
*/
|
|
100
|
+
type LoggerTypesConfig<T extends string, L extends string> = Record<T, Partial<LoggerConfiguration<L>>>;
|
|
101
|
+
/**
|
|
102
|
+
* Default Logger Types Configuration.
|
|
103
|
+
*
|
|
104
|
+
* A complete mapping of all default log types to their full configurations.
|
|
105
|
+
* @template L - Log level types
|
|
106
|
+
*/
|
|
107
|
+
type DefaultLoggerTypes<L extends string = string> = Record<DefaultLogTypes, LoggerConfiguration<L>>;
|
|
108
|
+
/**
|
|
109
|
+
* Read-only Metadata.
|
|
110
|
+
*
|
|
111
|
+
* Immutable version of the Meta interface for use in reporters.
|
|
112
|
+
* @template L - The log level type
|
|
113
|
+
*/
|
|
114
|
+
type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
|
|
115
|
+
/**
|
|
116
|
+
* Reporter Interface.
|
|
117
|
+
*
|
|
118
|
+
* Base interface for all reporters. Reporters are responsible for
|
|
119
|
+
* outputting log messages to various destinations (console, files, etc.).
|
|
120
|
+
* @template L - The log level type
|
|
121
|
+
*/
|
|
122
|
+
interface Reporter<L extends string> {
|
|
123
|
+
log: (meta: ReadonlyMeta<L>) => void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Stream-Aware Reporter Interface.
|
|
127
|
+
*
|
|
128
|
+
* Extends Reporter with the ability to work with Node.js streams.
|
|
129
|
+
* Used for server-side reporters that need to write to stdout/stderr.
|
|
130
|
+
* @template L - The log level type
|
|
131
|
+
*/
|
|
132
|
+
interface StreamAwareReporter<L extends string> extends Reporter<L> {
|
|
133
|
+
/** Set the stderr stream for error output */
|
|
134
|
+
setStderr: (stderr: NodeJS.WriteStream) => void;
|
|
135
|
+
/** Set the stdout stream for standard output */
|
|
136
|
+
setStdout: (stdout: NodeJS.WriteStream) => void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Logger Types Aware Reporter Interface.
|
|
140
|
+
*
|
|
141
|
+
* Extends Reporter with the ability to receive logger type configurations.
|
|
142
|
+
* Allows reporters to customize their output based on logger types.
|
|
143
|
+
* @template T - Custom logger type names
|
|
144
|
+
* @template L - The log level type
|
|
145
|
+
*/
|
|
146
|
+
interface LoggerTypesAwareReporter<T extends string, L extends string> extends Reporter<L> {
|
|
147
|
+
/** Set the logger types configuration */
|
|
148
|
+
setLoggerTypes: (types: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>) => void;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Stringify-Aware Reporter Interface.
|
|
152
|
+
*
|
|
153
|
+
* Extends Reporter with the ability to receive a custom stringify function.
|
|
154
|
+
* Useful for reporters that need to serialize complex objects.
|
|
155
|
+
* @template L - The log level type
|
|
156
|
+
*/
|
|
157
|
+
interface StringifyAwareReporter<L extends string> extends Reporter<L> {
|
|
158
|
+
/** Set the stringify function for object serialization */
|
|
159
|
+
setStringify: (stringify: any) => void;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Processor Interface.
|
|
163
|
+
*
|
|
164
|
+
* Base interface for all processors. Processors can modify or enhance
|
|
165
|
+
* log metadata before it reaches reporters.
|
|
166
|
+
* @template L - The log level type
|
|
167
|
+
*/
|
|
168
|
+
interface Processor<L extends string> {
|
|
169
|
+
/** Process the log metadata */
|
|
170
|
+
process: (meta: Meta<L>) => Meta<L>;
|
|
171
|
+
}
|
|
172
|
+
interface ConstructorOptions<T extends string, L extends string> {
|
|
173
|
+
disabled?: boolean;
|
|
174
|
+
logLevel?: LiteralUnion<ExtendedRfc5424LogLevels, L>;
|
|
175
|
+
logLevels?: Partial<Record<ExtendedRfc5424LogLevels, number>> & Record<L, number>;
|
|
176
|
+
messages?: {
|
|
177
|
+
timerEnd?: string;
|
|
178
|
+
timerStart?: string;
|
|
179
|
+
};
|
|
180
|
+
processors?: Processor<L>[];
|
|
181
|
+
rawReporter?: Reporter<L>;
|
|
182
|
+
reporters?: Reporter<L>[];
|
|
183
|
+
scope?: string[] | string;
|
|
184
|
+
throttle?: number;
|
|
185
|
+
throttleMin?: number;
|
|
186
|
+
types?: LoggerTypesConfig<T, L> & Partial<LoggerTypesConfig<DefaultLogTypes, L>>;
|
|
187
|
+
}
|
|
188
|
+
type Message = {
|
|
189
|
+
context?: any[];
|
|
190
|
+
message: any;
|
|
191
|
+
prefix?: string;
|
|
192
|
+
suffix?: string;
|
|
193
|
+
};
|
|
194
|
+
export { ConstructorOptions as C, DefaultLogTypes as D, ExtendedRfc5424LogLevels as E, LoggerTypesConfig as L, Meta as M, Processor as P, ReadonlyMeta as R, StringifyAwareReporter as S, LoggerTypesAwareReporter as a, Reporter as b, LoggerFunction as c, DefaultLoggerTypes as d, LoggerConfiguration as e, StreamAwareReporter as f };
|