@loglayer/mixin-datadog-http-metrics 1.0.0 → 2.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/LICENSE +1 -1
- package/dist/index.cjs +50 -3
- package/dist/index.d.cts +654 -85
- package/dist/index.d.mts +654 -85
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
import metrics, { BufferedMetricsLogger as BufferedMetricsLogger$1, BufferedMetricsLoggerOptions, BufferedMetricsLoggerOptions as BufferedMetricsLoggerOptions$1 } from "datadog-metrics";
|
|
2
2
|
|
|
3
3
|
//#region ../../core/shared/dist/index.d.ts
|
|
4
|
+
//#region src/lazy.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Symbol used to identify lazy values in context and metadata.
|
|
7
|
+
* Can be used to check if a value is a lazy wrapper: `LAZY_SYMBOL in value`.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://loglayer.dev/logging-api/lazy-evaluation | Lazy Evaluation Docs}
|
|
10
|
+
*/
|
|
11
|
+
declare const LAZY_SYMBOL: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* String constant used as a replacement value when a lazy callback fails during evaluation.
|
|
14
|
+
* Exported so users can programmatically detect lazy evaluation failures in their log output.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://loglayer.dev/logging-api/lazy-evaluation#error-handling | Lazy Evaluation Error Handling Docs}
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Represents a lazy value that defers evaluation until log time.
|
|
20
|
+
*
|
|
21
|
+
* Created by the {@link lazy} function.
|
|
22
|
+
*
|
|
23
|
+
* When the type parameter `T` is a `Promise`, log methods that receive this
|
|
24
|
+
* lazy value in metadata will return `Promise<void>` instead of `void`.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://loglayer.dev/logging-api/lazy-evaluation | Lazy Evaluation Docs}
|
|
27
|
+
*/
|
|
28
|
+
interface LazyLogValue<T = any> {
|
|
29
|
+
[LAZY_SYMBOL]: () => T;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Wraps a callback function to defer its evaluation until log time.
|
|
33
|
+
*
|
|
34
|
+
* The callback will only be invoked if the log level is enabled,
|
|
35
|
+
* avoiding unnecessary computation for disabled log levels.
|
|
36
|
+
*
|
|
37
|
+
* Can be used in both `withContext()` and `withMetadata()` at the root level.
|
|
38
|
+
*
|
|
39
|
+
* When the callback returns a `Promise` (i.e., is an async function), the
|
|
40
|
+
* log method will return `Promise<void>` so TypeScript can track that the
|
|
41
|
+
* operation is asynchronous.
|
|
42
|
+
*
|
|
43
|
+
* Adapted from [LogTape's lazy evaluation](https://logtape.org/manual/lazy).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { LogLayer, lazy } from "loglayer";
|
|
48
|
+
*
|
|
49
|
+
* const log = new LogLayer({ ... });
|
|
50
|
+
*
|
|
51
|
+
* // Dynamic context - evaluated on each log call
|
|
52
|
+
* log.withContext({
|
|
53
|
+
* memoryUsage: lazy(() => process.memoryUsage().heapUsed),
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Dynamic metadata - evaluated only if debug is enabled
|
|
57
|
+
* log.withMetadata({
|
|
58
|
+
* data: lazy(() => JSON.stringify(largeObject)),
|
|
59
|
+
* }).debug("Processing complete");
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://loglayer.dev/logging-api/lazy-evaluation | Lazy Evaluation Docs}
|
|
63
|
+
*/
|
|
64
|
+
//#endregion
|
|
4
65
|
//#region src/common.types.d.ts
|
|
5
66
|
declare enum LogLevel {
|
|
6
67
|
info = "info",
|
|
@@ -26,7 +87,7 @@ interface ErrorOnlyOpts {
|
|
|
26
87
|
/**
|
|
27
88
|
* Sets the log level of the error
|
|
28
89
|
*/
|
|
29
|
-
logLevel?:
|
|
90
|
+
logLevel?: LogLevelType;
|
|
30
91
|
/**
|
|
31
92
|
* If `true`, copies the `error.message` if available to the transport library's
|
|
32
93
|
* message property.
|
|
@@ -50,6 +111,49 @@ interface LogLayerMetadata extends Record<string, any> {}
|
|
|
50
111
|
* Used internally by LogLayer when assembling the final data object (metadata / context / error) sent to transports.
|
|
51
112
|
*/
|
|
52
113
|
interface LogLayerData extends Record<string, any> {}
|
|
114
|
+
/**
|
|
115
|
+
* Type-level helper that checks whether a metadata/context record type
|
|
116
|
+
* contains any {@link LazyLogValue} whose callback returns a `Promise`.
|
|
117
|
+
*
|
|
118
|
+
* Evaluates to `true` if any property is `LazyLogValue<Promise<any>>`,
|
|
119
|
+
* `false` otherwise. Returns `false` for `undefined` or `null` inputs.
|
|
120
|
+
*
|
|
121
|
+
* @see {@link https://loglayer.dev/logging-api/lazy-evaluation | Lazy Evaluation Docs}
|
|
122
|
+
*/
|
|
123
|
+
type ContainsAsyncLazy<M> = M extends undefined | null ? false : true extends { [K in keyof M]: M[K] extends LazyLogValue<infer T> ? (T extends Promise<any> ? true : false) : false }[keyof M] ? true : false;
|
|
124
|
+
/**
|
|
125
|
+
* Helper type that resolves the return type of log methods based on whether
|
|
126
|
+
* async lazy values are present.
|
|
127
|
+
*
|
|
128
|
+
* - `true` → `Promise<void>` (async lazy values detected)
|
|
129
|
+
* - `false` → `void` (no async lazy values)
|
|
130
|
+
* - `boolean` → `void | Promise<void>` (indeterminate, used by implementation classes)
|
|
131
|
+
*/
|
|
132
|
+
type LogReturnType<IsAsync extends boolean> = IsAsync extends true ? Promise<void> : IsAsync extends false ? void : void | Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Configuration for a single log group.
|
|
135
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
136
|
+
*/
|
|
137
|
+
interface LogGroupConfig {
|
|
138
|
+
/**
|
|
139
|
+
* Array of transport IDs that this group routes to.
|
|
140
|
+
*/
|
|
141
|
+
transports: string[];
|
|
142
|
+
/**
|
|
143
|
+
* Minimum log level for this group. Logs below this level are dropped
|
|
144
|
+
* for this group's transports. Default is "trace" (all levels pass).
|
|
145
|
+
*/
|
|
146
|
+
level?: LogLevelType;
|
|
147
|
+
/**
|
|
148
|
+
* Whether this group is enabled. Default is true.
|
|
149
|
+
*/
|
|
150
|
+
enabled?: boolean;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Map of group names to their configurations.
|
|
154
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
155
|
+
*/
|
|
156
|
+
type LogGroupsConfig = Record<string, LogGroupConfig>;
|
|
53
157
|
interface LogLayerCommonDataParams {
|
|
54
158
|
/**
|
|
55
159
|
* Combined object data containing the metadata, context, and / or error data in a
|
|
@@ -70,6 +174,37 @@ interface LogLayerCommonDataParams {
|
|
|
70
174
|
context?: LogLayerContext;
|
|
71
175
|
} //#endregion
|
|
72
176
|
//#region src/plugin.types.d.ts
|
|
177
|
+
/**
|
|
178
|
+
* Schema information for navigating the assembled log data.
|
|
179
|
+
*
|
|
180
|
+
* Contains the resolved field names used when assembling the log data,
|
|
181
|
+
* so plugins can navigate Data precisely (e.g., find the error map at
|
|
182
|
+
* errorFieldName).
|
|
183
|
+
*
|
|
184
|
+
* @note Only `errorFieldName` is guaranteed to be present. `contextFieldName`
|
|
185
|
+
* and `metadataFieldName` are `undefined` when their respective data is merged
|
|
186
|
+
* at the root level of the data object (i.e., when `contextFieldName` or
|
|
187
|
+
* `metadataFieldName` is not configured in LogLayer).
|
|
188
|
+
*
|
|
189
|
+
* @see {@link https://loglayer.dev/plugins/creating-plugins.html | Creating Plugins}
|
|
190
|
+
*/
|
|
191
|
+
interface LogLayerPluginSchema {
|
|
192
|
+
/**
|
|
193
|
+
* The key under which persistent context data is nested in data.
|
|
194
|
+
* `undefined` when context is merged at root level.
|
|
195
|
+
*/
|
|
196
|
+
contextFieldName?: string;
|
|
197
|
+
/**
|
|
198
|
+
* The key under which per-call metadata is nested in data.
|
|
199
|
+
* `undefined` when metadata is merged at root level.
|
|
200
|
+
*/
|
|
201
|
+
metadataFieldName?: string;
|
|
202
|
+
/**
|
|
203
|
+
* The key under which the serialized error is stored in data.
|
|
204
|
+
* Always populated; defaults to "err".
|
|
205
|
+
*/
|
|
206
|
+
errorFieldName: string;
|
|
207
|
+
}
|
|
73
208
|
/**
|
|
74
209
|
* Input for the `onBeforeDataOut` plugin lifecycle method.
|
|
75
210
|
* @see {@link https://loglayer.dev/plugins/creating-plugins.html#onbeforedataout | Creating Plugins}
|
|
@@ -79,6 +214,21 @@ interface PluginBeforeDataOutParams extends LogLayerCommonDataParams {
|
|
|
79
214
|
* Log level of the data
|
|
80
215
|
*/
|
|
81
216
|
logLevel: LogLevelType;
|
|
217
|
+
/**
|
|
218
|
+
* The group names this log entry belongs to, if any.
|
|
219
|
+
*
|
|
220
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
221
|
+
*/
|
|
222
|
+
groups?: string[];
|
|
223
|
+
/**
|
|
224
|
+
* Schema information for navigating the assembled data.
|
|
225
|
+
*/
|
|
226
|
+
schema?: LogLayerPluginSchema;
|
|
227
|
+
/**
|
|
228
|
+
* The prefix attached via withPrefix() on the emitting logger (or set
|
|
229
|
+
* via config.prefix). Empty when no prefix was set.
|
|
230
|
+
*/
|
|
231
|
+
prefix?: string;
|
|
82
232
|
}
|
|
83
233
|
/**
|
|
84
234
|
* Input for the `transformLogLevel` plugin lifecycle method.
|
|
@@ -93,6 +243,21 @@ interface PluginTransformLogLevelParams extends LogLayerCommonDataParams {
|
|
|
93
243
|
* Message data that is copied from the original.
|
|
94
244
|
*/
|
|
95
245
|
messages: any[];
|
|
246
|
+
/**
|
|
247
|
+
* The group names this log entry belongs to, if any.
|
|
248
|
+
*
|
|
249
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
250
|
+
*/
|
|
251
|
+
groups?: string[];
|
|
252
|
+
/**
|
|
253
|
+
* Schema information for navigating the assembled data.
|
|
254
|
+
*/
|
|
255
|
+
schema?: LogLayerPluginSchema;
|
|
256
|
+
/**
|
|
257
|
+
* The prefix attached via withPrefix() on the emitting logger (or set
|
|
258
|
+
* via config.prefix). Empty when no prefix was set.
|
|
259
|
+
*/
|
|
260
|
+
prefix?: string;
|
|
96
261
|
}
|
|
97
262
|
/**
|
|
98
263
|
* Input for the `shouldSendToLogger` plugin lifecycle method.
|
|
@@ -111,6 +276,21 @@ interface PluginShouldSendToLoggerParams extends LogLayerCommonDataParams {
|
|
|
111
276
|
* Log level of the message
|
|
112
277
|
*/
|
|
113
278
|
logLevel: LogLevelType;
|
|
279
|
+
/**
|
|
280
|
+
* The group names this log entry belongs to, if any.
|
|
281
|
+
*
|
|
282
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
283
|
+
*/
|
|
284
|
+
groups?: string[];
|
|
285
|
+
/**
|
|
286
|
+
* Schema information for navigating the assembled data.
|
|
287
|
+
*/
|
|
288
|
+
schema?: LogLayerPluginSchema;
|
|
289
|
+
/**
|
|
290
|
+
* The prefix attached via withPrefix() on the emitting logger (or set
|
|
291
|
+
* via config.prefix). Empty when no prefix was set.
|
|
292
|
+
*/
|
|
293
|
+
prefix?: string;
|
|
114
294
|
}
|
|
115
295
|
/**
|
|
116
296
|
* Input for the `onBeforeMessageOut` plugin lifecycle method.
|
|
@@ -125,6 +305,21 @@ interface PluginBeforeMessageOutParams {
|
|
|
125
305
|
* Message data that is copied from the original.
|
|
126
306
|
*/
|
|
127
307
|
messages: any[];
|
|
308
|
+
/**
|
|
309
|
+
* The group names this log entry belongs to, if any.
|
|
310
|
+
*
|
|
311
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
312
|
+
*/
|
|
313
|
+
groups?: string[];
|
|
314
|
+
/**
|
|
315
|
+
* Schema information for navigating the assembled data.
|
|
316
|
+
*/
|
|
317
|
+
schema?: LogLayerPluginSchema;
|
|
318
|
+
/**
|
|
319
|
+
* The prefix attached via withPrefix() on the emitting logger (or set
|
|
320
|
+
* via config.prefix). Empty when no prefix was set.
|
|
321
|
+
*/
|
|
322
|
+
prefix?: string;
|
|
128
323
|
}
|
|
129
324
|
/**
|
|
130
325
|
* Parameters for creating a LogLayer plugin.
|
|
@@ -430,6 +625,21 @@ interface LogLayerTransportParams extends LogLayerCommonDataParams {
|
|
|
430
625
|
* If true, the data object is included in the message parameters
|
|
431
626
|
*/
|
|
432
627
|
hasData?: boolean;
|
|
628
|
+
/**
|
|
629
|
+
* The group names this log entry belongs to, if any.
|
|
630
|
+
*
|
|
631
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
632
|
+
*/
|
|
633
|
+
groups?: string[];
|
|
634
|
+
/**
|
|
635
|
+
* Schema information for navigating the assembled data.
|
|
636
|
+
*/
|
|
637
|
+
schema?: LogLayerPluginSchema;
|
|
638
|
+
/**
|
|
639
|
+
* The prefix attached via withPrefix() on the emitting logger (or set
|
|
640
|
+
* via config.prefix). Empty when no prefix was set.
|
|
641
|
+
*/
|
|
642
|
+
prefix?: string;
|
|
433
643
|
}
|
|
434
644
|
/**
|
|
435
645
|
* Interface for implementing a LogLayer transport instance.
|
|
@@ -461,57 +671,112 @@ interface LogLayerTransport<LogLibrary = any> {
|
|
|
461
671
|
}
|
|
462
672
|
/**
|
|
463
673
|
* Interface for implementing a LogLayer builder instance.
|
|
674
|
+
*
|
|
675
|
+
* @typeParam This - The concrete builder type for polymorphic chaining.
|
|
676
|
+
* @typeParam IsAsync - Whether the builder contains async lazy metadata.
|
|
677
|
+
* When `true`, log methods return `Promise<void>`. When `false`, they return `void`.
|
|
678
|
+
* When `boolean` (indeterminate), they return `void | Promise<void>`.
|
|
679
|
+
*
|
|
464
680
|
* @see {@link https://loglayer.dev | LogLayer Documentation}
|
|
465
681
|
*/
|
|
466
|
-
interface ILogBuilder<This = ILogBuilder<any
|
|
682
|
+
interface ILogBuilder<This = ILogBuilder<any, any>, IsAsync extends boolean = false> {
|
|
467
683
|
/**
|
|
468
684
|
* Sends a log message to the logging library under an info log level.
|
|
685
|
+
* Returns a Promise when async lazy values are present in metadata.
|
|
686
|
+
*
|
|
687
|
+
* Supports tagged template syntax:
|
|
688
|
+
* ```typescript
|
|
689
|
+
* log.withMetadata({ userId }).info`User ${userId} logged in`;
|
|
690
|
+
* ```
|
|
469
691
|
*/
|
|
470
|
-
info(...
|
|
692
|
+
info(strings: TemplateStringsArray, ...values: any[]): LogReturnType<IsAsync>;
|
|
693
|
+
info(...messages: MessageDataType[]): LogReturnType<IsAsync>;
|
|
471
694
|
/**
|
|
472
|
-
* Sends a log message to the logging library under the warn log level
|
|
695
|
+
* Sends a log message to the logging library under the warn log level.
|
|
696
|
+
* Returns a Promise when async lazy values are present in metadata.
|
|
697
|
+
*
|
|
698
|
+
* Supports tagged template syntax:
|
|
699
|
+
* ```typescript
|
|
700
|
+
* log.withMetadata({ requestId }).warn`Request ${requestId} timed out`;
|
|
701
|
+
* ```
|
|
473
702
|
*/
|
|
474
|
-
warn(...
|
|
703
|
+
warn(strings: TemplateStringsArray, ...values: any[]): LogReturnType<IsAsync>;
|
|
704
|
+
warn(...messages: MessageDataType[]): LogReturnType<IsAsync>;
|
|
475
705
|
/**
|
|
476
|
-
* Sends a log message to the logging library under the error log level
|
|
706
|
+
* Sends a log message to the logging library under the error log level.
|
|
707
|
+
* Returns a Promise when async lazy values are present in metadata.
|
|
708
|
+
*
|
|
709
|
+
* Supports tagged template syntax:
|
|
710
|
+
* ```typescript
|
|
711
|
+
* log.withError(err).error`Failed to process ${taskId}`;
|
|
712
|
+
* ```
|
|
477
713
|
*/
|
|
478
|
-
error(...
|
|
714
|
+
error(strings: TemplateStringsArray, ...values: any[]): LogReturnType<IsAsync>;
|
|
715
|
+
error(...messages: MessageDataType[]): LogReturnType<IsAsync>;
|
|
479
716
|
/**
|
|
480
|
-
* Sends a log message to the logging library under the debug log level
|
|
717
|
+
* Sends a log message to the logging library under the debug log level.
|
|
718
|
+
* Returns a Promise when async lazy values are present in metadata.
|
|
719
|
+
*
|
|
720
|
+
* Supports tagged template syntax:
|
|
721
|
+
* ```typescript
|
|
722
|
+
* log.withMetadata({ cacheKey }).debug`Cache hit for ${cacheKey}`;
|
|
723
|
+
* ```
|
|
481
724
|
*/
|
|
482
|
-
debug(...
|
|
725
|
+
debug(strings: TemplateStringsArray, ...values: any[]): LogReturnType<IsAsync>;
|
|
726
|
+
debug(...messages: MessageDataType[]): LogReturnType<IsAsync>;
|
|
483
727
|
/**
|
|
484
|
-
* Sends a log message to the logging library under the trace log level
|
|
728
|
+
* Sends a log message to the logging library under the trace log level.
|
|
729
|
+
* Returns a Promise when async lazy values are present in metadata.
|
|
730
|
+
*
|
|
731
|
+
* Supports tagged template syntax:
|
|
732
|
+
* ```typescript
|
|
733
|
+
* log.withMetadata({ functionName }).trace`Entering ${functionName}`;
|
|
734
|
+
* ```
|
|
485
735
|
*/
|
|
486
|
-
trace(...
|
|
736
|
+
trace(strings: TemplateStringsArray, ...values: any[]): LogReturnType<IsAsync>;
|
|
737
|
+
trace(...messages: MessageDataType[]): LogReturnType<IsAsync>;
|
|
487
738
|
/**
|
|
488
|
-
* Sends a log message to the logging library under the fatal log level
|
|
739
|
+
* Sends a log message to the logging library under the fatal log level.
|
|
740
|
+
* Returns a Promise when async lazy values are present in metadata.
|
|
741
|
+
*
|
|
742
|
+
* Supports tagged template syntax:
|
|
743
|
+
* ```typescript
|
|
744
|
+
* log.withError(err).fatal`System crash: ${reason}`;
|
|
745
|
+
* ```
|
|
489
746
|
*/
|
|
490
|
-
fatal(...
|
|
747
|
+
fatal(strings: TemplateStringsArray, ...values: any[]): LogReturnType<IsAsync>;
|
|
748
|
+
fatal(...messages: MessageDataType[]): LogReturnType<IsAsync>;
|
|
491
749
|
/**
|
|
492
|
-
* Specifies metadata to include with the log message
|
|
750
|
+
* Specifies metadata to include with the log message.
|
|
751
|
+
* If the metadata contains async lazy values, subsequent log methods will return `Promise<void>`.
|
|
493
752
|
*
|
|
494
753
|
* @see {@link https://loglayer.dev/logging-api/metadata.html | Metadata Docs}
|
|
495
754
|
*/
|
|
496
|
-
withMetadata(metadata?:
|
|
755
|
+
withMetadata<M extends LogLayerMetadata>(metadata?: M): ILogBuilder<This, ContainsAsyncLazy<NonNullable<M>> extends true ? true : IsAsync>;
|
|
497
756
|
/**
|
|
498
757
|
* Specifies an Error to include with the log message
|
|
499
758
|
*
|
|
500
759
|
* @see {@link https://loglayer.dev/logging-api/error-handling.html | Error Handling Docs}
|
|
501
760
|
*/
|
|
502
|
-
withError(error: any): This
|
|
761
|
+
withError(error: any): ILogBuilder<This, IsAsync>;
|
|
762
|
+
/**
|
|
763
|
+
* Tags this log entry with one or more groups for routing.
|
|
764
|
+
*
|
|
765
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
766
|
+
*/
|
|
767
|
+
withGroup(group: string | string[]): ILogBuilder<This, IsAsync>;
|
|
503
768
|
/**
|
|
504
769
|
* Enable sending logs to the logging library.
|
|
505
770
|
*
|
|
506
771
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html#enabling-disabling-logging | Enabling/Disabling Logging Docs}
|
|
507
772
|
*/
|
|
508
|
-
enableLogging(): This
|
|
773
|
+
enableLogging(): ILogBuilder<This, IsAsync>;
|
|
509
774
|
/**
|
|
510
775
|
* All logging inputs are dropped and stops sending logs to the logging library.
|
|
511
776
|
*
|
|
512
777
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html#enabling-disabling-logging | Enabling/Disabling Logging Docs}
|
|
513
778
|
*/
|
|
514
|
-
disableLogging(): This
|
|
779
|
+
disableLogging(): ILogBuilder<This, IsAsync>;
|
|
515
780
|
}
|
|
516
781
|
/**
|
|
517
782
|
* Interface for implementing a LogLayer logger instance.
|
|
@@ -520,40 +785,77 @@ interface ILogBuilder<This = ILogBuilder<any>> {
|
|
|
520
785
|
interface ILogLayer<This = ILogLayer<any>> {
|
|
521
786
|
/**
|
|
522
787
|
* Sends a log message to the logging library under an info log level.
|
|
788
|
+
*
|
|
789
|
+
* Supports tagged template syntax:
|
|
790
|
+
* ```typescript
|
|
791
|
+
* log.info`User ${userId} logged in`;
|
|
792
|
+
* ```
|
|
523
793
|
*/
|
|
794
|
+
info(strings: TemplateStringsArray, ...values: any[]): void;
|
|
524
795
|
info(...messages: MessageDataType[]): void;
|
|
525
796
|
/**
|
|
526
|
-
* Sends a log message to the logging library under the warn log level
|
|
797
|
+
* Sends a log message to the logging library under the warn log level.
|
|
798
|
+
*
|
|
799
|
+
* Supports tagged template syntax:
|
|
800
|
+
* ```typescript
|
|
801
|
+
* log.warn`Request ${requestId} timed out`;
|
|
802
|
+
* ```
|
|
527
803
|
*/
|
|
804
|
+
warn(strings: TemplateStringsArray, ...values: any[]): void;
|
|
528
805
|
warn(...messages: MessageDataType[]): void;
|
|
529
806
|
/**
|
|
530
|
-
* Sends a log message to the logging library under the error log level
|
|
807
|
+
* Sends a log message to the logging library under the error log level.
|
|
808
|
+
*
|
|
809
|
+
* Supports tagged template syntax:
|
|
810
|
+
* ```typescript
|
|
811
|
+
* log.error`Failed to process ${taskId}`;
|
|
812
|
+
* ```
|
|
531
813
|
*/
|
|
814
|
+
error(strings: TemplateStringsArray, ...values: any[]): void;
|
|
532
815
|
error(...messages: MessageDataType[]): void;
|
|
533
816
|
/**
|
|
534
|
-
* Sends a log message to the logging library under the debug log level
|
|
817
|
+
* Sends a log message to the logging library under the debug log level.
|
|
818
|
+
*
|
|
819
|
+
* Supports tagged template syntax:
|
|
820
|
+
* ```typescript
|
|
821
|
+
* log.debug`Cache hit for ${cacheKey}`;
|
|
822
|
+
* ```
|
|
535
823
|
*/
|
|
824
|
+
debug(strings: TemplateStringsArray, ...values: any[]): void;
|
|
536
825
|
debug(...messages: MessageDataType[]): void;
|
|
537
826
|
/**
|
|
538
|
-
* Sends a log message to the logging library under the trace log level
|
|
827
|
+
* Sends a log message to the logging library under the trace log level.
|
|
828
|
+
*
|
|
829
|
+
* Supports tagged template syntax:
|
|
830
|
+
* ```typescript
|
|
831
|
+
* log.trace`Entering ${functionName}`;
|
|
832
|
+
* ```
|
|
539
833
|
*/
|
|
834
|
+
trace(strings: TemplateStringsArray, ...values: any[]): void;
|
|
540
835
|
trace(...messages: MessageDataType[]): void;
|
|
541
836
|
/**
|
|
542
|
-
* Sends a log message to the logging library under the fatal log level
|
|
837
|
+
* Sends a log message to the logging library under the fatal log level.
|
|
838
|
+
*
|
|
839
|
+
* Supports tagged template syntax:
|
|
840
|
+
* ```typescript
|
|
841
|
+
* log.fatal`System crash: ${reason}`;
|
|
842
|
+
* ```
|
|
543
843
|
*/
|
|
844
|
+
fatal(strings: TemplateStringsArray, ...values: any[]): void;
|
|
544
845
|
fatal(...messages: MessageDataType[]): void;
|
|
545
846
|
/**
|
|
546
|
-
* Specifies metadata to include with the log message
|
|
847
|
+
* Specifies metadata to include with the log message.
|
|
848
|
+
* If the metadata contains async lazy values, the builder's log methods will return `Promise<void>`.
|
|
547
849
|
*
|
|
548
850
|
* @see {@link https://loglayer.dev/logging-api/metadata.html | Metadata Docs}
|
|
549
851
|
*/
|
|
550
|
-
withMetadata(metadata?:
|
|
852
|
+
withMetadata<M extends LogLayerMetadata>(metadata?: M): ILogBuilder<any, ContainsAsyncLazy<NonNullable<M>>>;
|
|
551
853
|
/**
|
|
552
854
|
* Specifies an Error to include with the log message
|
|
553
855
|
*
|
|
554
856
|
* @see {@link https://loglayer.dev/logging-api/error-handling.html | Error Handling Docs}
|
|
555
857
|
*/
|
|
556
|
-
withError(error: any): ILogBuilder<any>;
|
|
858
|
+
withError(error: any): ILogBuilder<any, false>;
|
|
557
859
|
/**
|
|
558
860
|
* Enable sending logs to the logging library.
|
|
559
861
|
*
|
|
@@ -572,6 +874,57 @@ interface ILogLayer<This = ILogLayer<any>> {
|
|
|
572
874
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html#message-prefixing | Message Prefixing Docs}
|
|
573
875
|
*/
|
|
574
876
|
withPrefix(string: string): This;
|
|
877
|
+
/**
|
|
878
|
+
* Creates a child logger with the specified group(s) persistently assigned.
|
|
879
|
+
* All logs from the child will be tagged with these groups.
|
|
880
|
+
*
|
|
881
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
882
|
+
*/
|
|
883
|
+
withGroup(group: string | string[]): This;
|
|
884
|
+
/**
|
|
885
|
+
* Adds a new group definition at runtime.
|
|
886
|
+
*
|
|
887
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
888
|
+
*/
|
|
889
|
+
addGroup(name: string, config: LogGroupConfig): This;
|
|
890
|
+
/**
|
|
891
|
+
* Removes a group definition at runtime.
|
|
892
|
+
*
|
|
893
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
894
|
+
*/
|
|
895
|
+
removeGroup(name: string): This;
|
|
896
|
+
/**
|
|
897
|
+
* Enables a group by name (sets enabled: true).
|
|
898
|
+
*
|
|
899
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
900
|
+
*/
|
|
901
|
+
enableGroup(name: string): This;
|
|
902
|
+
/**
|
|
903
|
+
* Disables a group by name (sets enabled: false). Logs tagged with a disabled
|
|
904
|
+
* group will not be routed through that group.
|
|
905
|
+
*
|
|
906
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
907
|
+
*/
|
|
908
|
+
disableGroup(name: string): This;
|
|
909
|
+
/**
|
|
910
|
+
* Sets the minimum log level for a group at runtime.
|
|
911
|
+
*
|
|
912
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
913
|
+
*/
|
|
914
|
+
setGroupLevel(name: string, level: LogLevelType): This;
|
|
915
|
+
/**
|
|
916
|
+
* Sets which groups are active. Only active groups will route logs.
|
|
917
|
+
* Pass null to clear the filter (all groups active).
|
|
918
|
+
*
|
|
919
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
920
|
+
*/
|
|
921
|
+
setActiveGroups(groups: string[] | null): This;
|
|
922
|
+
/**
|
|
923
|
+
* Returns a snapshot of all group configurations.
|
|
924
|
+
*
|
|
925
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
926
|
+
*/
|
|
927
|
+
getGroups(): LogGroupsConfig;
|
|
575
928
|
/**
|
|
576
929
|
* Appends context data which will be included with
|
|
577
930
|
* every log entry.
|
|
@@ -597,17 +950,23 @@ interface ILogLayer<This = ILogLayer<any>> {
|
|
|
597
950
|
*/
|
|
598
951
|
errorOnly(error: any, opts?: ErrorOnlyOpts): void;
|
|
599
952
|
/**
|
|
600
|
-
* Logs only metadata without a log message
|
|
953
|
+
* Logs only metadata without a log message.
|
|
954
|
+
* Returns a Promise when async lazy values are present in metadata.
|
|
601
955
|
*
|
|
602
956
|
* @see {@link https://loglayer.dev/logging-api/metadata.html | Metadata Docs}
|
|
603
957
|
*/
|
|
604
|
-
metadataOnly(metadata?:
|
|
958
|
+
metadataOnly<M extends LogLayerMetadata>(metadata?: M, logLevel?: LogLevelType): LogReturnType<ContainsAsyncLazy<NonNullable<M>>>;
|
|
605
959
|
/**
|
|
606
|
-
* Returns the context used
|
|
960
|
+
* Returns the context used.
|
|
961
|
+
* By default, lazy values are resolved before returning.
|
|
962
|
+
* Pass `{ raw: true }` to return the raw lazy wrappers without resolving them.
|
|
963
|
+
* Async lazy values in context are not supported and will be replaced with `"[LazyEvalError]"`.
|
|
607
964
|
*
|
|
608
965
|
* @see {@link https://loglayer.dev/logging-api/context.html | Context Docs}
|
|
609
966
|
*/
|
|
610
|
-
getContext(
|
|
967
|
+
getContext(options?: {
|
|
968
|
+
raw?: boolean;
|
|
969
|
+
}): LogLayerContext;
|
|
611
970
|
/**
|
|
612
971
|
* Creates a new instance of LogLayer but with the initialization
|
|
613
972
|
* configuration and context data copied over.
|
|
@@ -769,6 +1128,9 @@ interface ILogLayer<This = ILogLayer<any>> {
|
|
|
769
1128
|
metadataFieldName?: string;
|
|
770
1129
|
muteContext?: boolean;
|
|
771
1130
|
muteMetadata?: boolean;
|
|
1131
|
+
groups?: LogGroupsConfig;
|
|
1132
|
+
activeGroups?: string[] | null;
|
|
1133
|
+
ungroupedBehavior?: "all" | "none" | string[];
|
|
772
1134
|
};
|
|
773
1135
|
/**
|
|
774
1136
|
* Logs a raw log entry with complete control over all log parameters.
|
|
@@ -780,11 +1142,28 @@ interface ILogLayer<This = ILogLayer<any>> {
|
|
|
780
1142
|
* systems that provide pre-formatted log entries.
|
|
781
1143
|
*
|
|
782
1144
|
* The raw entry will still go through all LogLayer processing.
|
|
1145
|
+
* Returns a Promise when async lazy values are present in the entry's metadata.
|
|
783
1146
|
*
|
|
784
1147
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
785
1148
|
*/
|
|
786
|
-
raw(rawEntry:
|
|
1149
|
+
raw<R extends RawLogEntry>(rawEntry: R): LogReturnType<ContainsAsyncLazy<NonNullable<R["metadata"]>>>;
|
|
787
1150
|
} //#endregion
|
|
1151
|
+
//#region src/template-utils.d.ts
|
|
1152
|
+
/**
|
|
1153
|
+
* Arguments from a tagged template literal call: [TemplateStringsArray, ...values]
|
|
1154
|
+
*/
|
|
1155
|
+
type TaggedTemplateArgs = [TemplateStringsArray, ...any[]];
|
|
1156
|
+
/**
|
|
1157
|
+
* Union of tagged template args and regular message args.
|
|
1158
|
+
* Used by log methods that accept both syntaxes:
|
|
1159
|
+
* - log.info\`Message ${value}\`
|
|
1160
|
+
* - log.info("Message", value)
|
|
1161
|
+
*/
|
|
1162
|
+
type TaggedTemplateOrMessageArgs = TaggedTemplateArgs | MessageDataType[];
|
|
1163
|
+
/**
|
|
1164
|
+
* Converts tagged template arguments to a message array.
|
|
1165
|
+
* Detects tagged templates by checking for the `raw` property on TemplateStringsArray.
|
|
1166
|
+
*/
|
|
788
1167
|
//#endregion
|
|
789
1168
|
//#region ../../core/plugin/dist/index.d.ts
|
|
790
1169
|
/**
|
|
@@ -857,17 +1236,18 @@ declare class PluginManager {
|
|
|
857
1236
|
* A mock implementation of the ILogBuilder interface that does nothing.
|
|
858
1237
|
* Useful for writing unit tests.
|
|
859
1238
|
*/
|
|
860
|
-
declare class MockLogBuilder implements ILogBuilder<MockLogBuilder> {
|
|
861
|
-
debug(...
|
|
862
|
-
error(...
|
|
863
|
-
info(...
|
|
864
|
-
trace(...
|
|
865
|
-
warn(...
|
|
866
|
-
fatal(...
|
|
1239
|
+
declare class MockLogBuilder implements ILogBuilder<MockLogBuilder, false> {
|
|
1240
|
+
debug(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1241
|
+
error(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1242
|
+
info(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1243
|
+
trace(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1244
|
+
warn(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1245
|
+
fatal(..._args: TaggedTemplateOrMessageArgs): void;
|
|
867
1246
|
enableLogging(): this;
|
|
868
1247
|
disableLogging(): this;
|
|
869
|
-
withMetadata(_metadata?: Record<string, any>):
|
|
870
|
-
withError(_error: any):
|
|
1248
|
+
withMetadata(_metadata?: Record<string, any>): any;
|
|
1249
|
+
withError(_error: any): any;
|
|
1250
|
+
withGroup(_group: string | string[]): any;
|
|
871
1251
|
} //#endregion
|
|
872
1252
|
//#region src/MockLogLayer.d.ts
|
|
873
1253
|
/**
|
|
@@ -875,29 +1255,39 @@ declare class MockLogBuilder implements ILogBuilder<MockLogBuilder> {
|
|
|
875
1255
|
* Useful for writing unit tests.
|
|
876
1256
|
* MockLogLayer implements both ILogLayer and ILogBuilder for simplicity in testing.
|
|
877
1257
|
*/
|
|
878
|
-
declare class MockLogLayer$1 implements ILogLayer<MockLogLayer$1
|
|
1258
|
+
declare class MockLogLayer$1 implements ILogLayer<MockLogLayer$1> {
|
|
879
1259
|
private mockLogBuilder;
|
|
880
1260
|
private mockContextManager;
|
|
881
1261
|
private mockLogLevelManager;
|
|
882
|
-
info(...
|
|
883
|
-
warn(...
|
|
884
|
-
error(...
|
|
885
|
-
debug(...
|
|
886
|
-
trace(...
|
|
887
|
-
fatal(...
|
|
888
|
-
raw(_rawEntry: RawLogEntry):
|
|
1262
|
+
info(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1263
|
+
warn(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1264
|
+
error(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1265
|
+
debug(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1266
|
+
trace(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1267
|
+
fatal(..._args: TaggedTemplateOrMessageArgs): void;
|
|
1268
|
+
raw(_rawEntry: RawLogEntry): any;
|
|
889
1269
|
getLoggerInstance<_T extends LogLayerTransport>(_id: string): any;
|
|
890
1270
|
errorOnly(_error: any, _opts?: ErrorOnlyOpts): void;
|
|
891
|
-
metadataOnly(_metadata?: Record<string, any>, _logLevel?: LogLevel):
|
|
1271
|
+
metadataOnly(_metadata?: Record<string, any>, _logLevel?: LogLevel): any;
|
|
892
1272
|
addPlugins(_plugins: Array<LogLayerPlugin>): void;
|
|
893
1273
|
removePlugin(_id: string): void;
|
|
894
1274
|
enablePlugin(_id: string): void;
|
|
895
1275
|
disablePlugin(_id: string): void;
|
|
896
1276
|
withPrefix(_prefix: string): this;
|
|
1277
|
+
withGroup(_group: string | string[]): this;
|
|
1278
|
+
addGroup(_name: string, _config: LogGroupConfig): this;
|
|
1279
|
+
removeGroup(_name: string): this;
|
|
1280
|
+
enableGroup(_name: string): this;
|
|
1281
|
+
disableGroup(_name: string): this;
|
|
1282
|
+
setGroupLevel(_name: string, _level: LogLevelType): this;
|
|
1283
|
+
setActiveGroups(_groups: string[] | null): this;
|
|
1284
|
+
getGroups(): LogGroupsConfig;
|
|
897
1285
|
withContext(_context?: Record<string, any>): this;
|
|
898
|
-
withError(_error: any): any
|
|
899
|
-
withMetadata(_metadata?:
|
|
900
|
-
getContext(
|
|
1286
|
+
withError(_error: any): ILogBuilder<any, false>;
|
|
1287
|
+
withMetadata<M extends LogLayerMetadata>(_metadata?: M): ILogBuilder<any, ContainsAsyncLazy<NonNullable<M>>>;
|
|
1288
|
+
getContext(_options?: {
|
|
1289
|
+
raw?: boolean;
|
|
1290
|
+
}): Record<string, any>;
|
|
901
1291
|
clearContext(_keys?: string | string[]): this;
|
|
902
1292
|
enableLogging(): this;
|
|
903
1293
|
disableLogging(): this;
|
|
@@ -926,7 +1316,7 @@ declare class MockLogLayer$1 implements ILogLayer<MockLogLayer$1>, ILogBuilder<M
|
|
|
926
1316
|
/**
|
|
927
1317
|
* Returns the mock log builder used for testing.
|
|
928
1318
|
*/
|
|
929
|
-
getMockLogBuilder(): ILogBuilder<ILogBuilder<any
|
|
1319
|
+
getMockLogBuilder(): ILogBuilder<ILogBuilder<any, any>, false>;
|
|
930
1320
|
/**
|
|
931
1321
|
* Resets the mock log builder to a new instance of MockLogBuilder.
|
|
932
1322
|
*/
|
|
@@ -1107,6 +1497,32 @@ interface LogLayerConfig {
|
|
|
1107
1497
|
* If set to true, will not include metadata data in the log message.
|
|
1108
1498
|
*/
|
|
1109
1499
|
muteMetadata?: boolean;
|
|
1500
|
+
/**
|
|
1501
|
+
* Named routing groups. Each group defines which transports it routes to
|
|
1502
|
+
* and an optional minimum log level.
|
|
1503
|
+
*
|
|
1504
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1505
|
+
*/
|
|
1506
|
+
groups?: LogGroupsConfig;
|
|
1507
|
+
/**
|
|
1508
|
+
* When set, only these group names are active. Logs tagged with inactive
|
|
1509
|
+
* groups are dropped. The `LOGLAYER_GROUPS` env variable overrides this
|
|
1510
|
+
* at construction time.
|
|
1511
|
+
*
|
|
1512
|
+
* Set to `null` to clear the filter (all defined groups are active).
|
|
1513
|
+
*
|
|
1514
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1515
|
+
*/
|
|
1516
|
+
activeGroups?: string[] | null;
|
|
1517
|
+
/**
|
|
1518
|
+
* Controls what happens to logs that have NO group tags.
|
|
1519
|
+
* - `'all'` (default): ungrouped logs go to ALL transports (backward compatible).
|
|
1520
|
+
* - `'none'`: ungrouped logs are dropped entirely.
|
|
1521
|
+
* - `string[]`: ungrouped logs go only to the listed transport IDs.
|
|
1522
|
+
*
|
|
1523
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1524
|
+
*/
|
|
1525
|
+
ungroupedBehavior?: "all" | "none" | string[];
|
|
1110
1526
|
} //#endregion
|
|
1111
1527
|
//#region src/LogLayer.d.ts
|
|
1112
1528
|
interface FormatLogParams {
|
|
@@ -1115,6 +1531,7 @@ interface FormatLogParams {
|
|
|
1115
1531
|
metadata?: LogLayerMetadata | null;
|
|
1116
1532
|
err?: any;
|
|
1117
1533
|
context?: LogLayerContext | null;
|
|
1534
|
+
groups?: string[] | null;
|
|
1118
1535
|
}
|
|
1119
1536
|
/**
|
|
1120
1537
|
* Wraps around a logging framework to provide convenience methods that allow
|
|
@@ -1128,6 +1545,12 @@ declare class LogLayer$1 implements ILogLayer<LogLayer$1> {
|
|
|
1128
1545
|
private singleTransport;
|
|
1129
1546
|
private contextManager;
|
|
1130
1547
|
private logLevelManager;
|
|
1548
|
+
private _isLoggingLazyError;
|
|
1549
|
+
private _lazyContextCount;
|
|
1550
|
+
private _assignedGroups;
|
|
1551
|
+
private _groupsConfig;
|
|
1552
|
+
private _activeGroups;
|
|
1553
|
+
private _ungroupedBehavior;
|
|
1131
1554
|
/**
|
|
1132
1555
|
* The configuration object used to initialize the logger.
|
|
1133
1556
|
* This is for internal use only and should not be modified directly.
|
|
@@ -1161,6 +1584,56 @@ declare class LogLayer$1 implements ILogLayer<LogLayer$1> {
|
|
|
1161
1584
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html#message-prefixing | Message Prefixing Docs}
|
|
1162
1585
|
*/
|
|
1163
1586
|
withPrefix(prefix: string): LogLayer$1;
|
|
1587
|
+
/**
|
|
1588
|
+
* Creates a child logger with the specified group(s) persistently assigned.
|
|
1589
|
+
* All logs from the child will be tagged with these groups.
|
|
1590
|
+
*
|
|
1591
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1592
|
+
*/
|
|
1593
|
+
withGroup(group: string | string[]): LogLayer$1;
|
|
1594
|
+
/**
|
|
1595
|
+
* Adds a new group definition at runtime.
|
|
1596
|
+
*
|
|
1597
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1598
|
+
*/
|
|
1599
|
+
addGroup(name: string, config: LogGroupConfig): LogLayer$1;
|
|
1600
|
+
/**
|
|
1601
|
+
* Removes a group definition at runtime.
|
|
1602
|
+
*
|
|
1603
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1604
|
+
*/
|
|
1605
|
+
removeGroup(name: string): LogLayer$1;
|
|
1606
|
+
/**
|
|
1607
|
+
* Enables a group by name (sets enabled: true).
|
|
1608
|
+
*
|
|
1609
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1610
|
+
*/
|
|
1611
|
+
enableGroup(name: string): LogLayer$1;
|
|
1612
|
+
/**
|
|
1613
|
+
* Disables a group by name (sets enabled: false).
|
|
1614
|
+
*
|
|
1615
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1616
|
+
*/
|
|
1617
|
+
disableGroup(name: string): LogLayer$1;
|
|
1618
|
+
/**
|
|
1619
|
+
* Sets the minimum log level for a group at runtime.
|
|
1620
|
+
*
|
|
1621
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1622
|
+
*/
|
|
1623
|
+
setGroupLevel(name: string, level: LogLevelType): LogLayer$1;
|
|
1624
|
+
/**
|
|
1625
|
+
* Sets which groups are active. Only active groups will route logs.
|
|
1626
|
+
* Pass null to clear the filter (all groups active).
|
|
1627
|
+
*
|
|
1628
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1629
|
+
*/
|
|
1630
|
+
setActiveGroups(groups: string[] | null): LogLayer$1;
|
|
1631
|
+
/**
|
|
1632
|
+
* Returns a snapshot of all group configurations.
|
|
1633
|
+
*
|
|
1634
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1635
|
+
*/
|
|
1636
|
+
getGroups(): LogGroupsConfig;
|
|
1164
1637
|
/**
|
|
1165
1638
|
* Appends context data which will be included with
|
|
1166
1639
|
* every log entry.
|
|
@@ -1177,7 +1650,9 @@ declare class LogLayer$1 implements ILogLayer<LogLayer$1> {
|
|
|
1177
1650
|
* If no keys are provided, all context data will be cleared.
|
|
1178
1651
|
*/
|
|
1179
1652
|
clearContext(keys?: string | string[]): this;
|
|
1180
|
-
getContext(
|
|
1653
|
+
getContext(options?: {
|
|
1654
|
+
raw?: boolean;
|
|
1655
|
+
}): LogLayerContext;
|
|
1181
1656
|
/**
|
|
1182
1657
|
* Add additional plugins.
|
|
1183
1658
|
*
|
|
@@ -1207,13 +1682,13 @@ declare class LogLayer$1 implements ILogLayer<LogLayer$1> {
|
|
|
1207
1682
|
*
|
|
1208
1683
|
* @see {@link https://loglayer.dev/logging-api/metadata.html | Metadata Docs}
|
|
1209
1684
|
*/
|
|
1210
|
-
withMetadata(metadata?:
|
|
1685
|
+
withMetadata<M extends LogLayerMetadata>(metadata?: M): ILogBuilder<any, ContainsAsyncLazy<NonNullable<M>>>;
|
|
1211
1686
|
/**
|
|
1212
1687
|
* Specifies an Error to include with the log message
|
|
1213
1688
|
*
|
|
1214
1689
|
* @see {@link https://loglayer.dev/logging-api/error-handling.html | Error Handling Docs}
|
|
1215
1690
|
*/
|
|
1216
|
-
withError(error: any):
|
|
1691
|
+
withError(error: any): ILogBuilder<any, false>;
|
|
1217
1692
|
/**
|
|
1218
1693
|
* Creates a new instance of LogLayer but with the initialization
|
|
1219
1694
|
* configuration and context copied over.
|
|
@@ -1275,46 +1750,73 @@ declare class LogLayer$1 implements ILogLayer<LogLayer$1> {
|
|
|
1275
1750
|
*
|
|
1276
1751
|
* @see {@link https://loglayer.dev/logging-api/metadata.html | Metadata Docs}
|
|
1277
1752
|
*/
|
|
1278
|
-
metadataOnly(metadata?:
|
|
1753
|
+
metadataOnly<M extends LogLayerMetadata>(metadata?: M, logLevel?: LogLevelType): LogReturnType<ContainsAsyncLazy<NonNullable<M>>>;
|
|
1279
1754
|
/**
|
|
1280
1755
|
* Sends a log message to the logging library under an info log level.
|
|
1281
1756
|
*
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1757
|
+
* Supports tagged template syntax:
|
|
1758
|
+
* ```typescript
|
|
1759
|
+
* log.info`User ${userId} logged in`;
|
|
1760
|
+
* ```
|
|
1284
1761
|
*
|
|
1285
1762
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
1286
1763
|
*/
|
|
1287
|
-
info(...
|
|
1764
|
+
info(...args: TaggedTemplateOrMessageArgs): void;
|
|
1288
1765
|
/**
|
|
1289
1766
|
* Sends a log message to the logging library under the warn log level
|
|
1290
1767
|
*
|
|
1768
|
+
* Supports tagged template syntax:
|
|
1769
|
+
* ```typescript
|
|
1770
|
+
* log.warn`Request ${requestId} timed out`;
|
|
1771
|
+
* ```
|
|
1772
|
+
*
|
|
1291
1773
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
1292
1774
|
*/
|
|
1293
|
-
warn(...
|
|
1775
|
+
warn(...args: TaggedTemplateOrMessageArgs): void;
|
|
1294
1776
|
/**
|
|
1295
1777
|
* Sends a log message to the logging library under the error log level
|
|
1296
1778
|
*
|
|
1779
|
+
* Supports tagged template syntax:
|
|
1780
|
+
* ```typescript
|
|
1781
|
+
* log.error`Failed to process ${taskId}`;
|
|
1782
|
+
* ```
|
|
1783
|
+
*
|
|
1297
1784
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
1298
1785
|
*/
|
|
1299
|
-
error(...
|
|
1786
|
+
error(...args: TaggedTemplateOrMessageArgs): void;
|
|
1300
1787
|
/**
|
|
1301
1788
|
* Sends a log message to the logging library under the debug log level
|
|
1302
1789
|
*
|
|
1790
|
+
* Supports tagged template syntax:
|
|
1791
|
+
* ```typescript
|
|
1792
|
+
* log.debug`Cache hit for ${cacheKey}`;
|
|
1793
|
+
* ```
|
|
1794
|
+
*
|
|
1303
1795
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
1304
1796
|
*/
|
|
1305
|
-
debug(...
|
|
1797
|
+
debug(...args: TaggedTemplateOrMessageArgs): void;
|
|
1306
1798
|
/**
|
|
1307
1799
|
* Sends a log message to the logging library under the trace log level
|
|
1308
1800
|
*
|
|
1801
|
+
* Supports tagged template syntax:
|
|
1802
|
+
* ```typescript
|
|
1803
|
+
* log.trace`Entering ${functionName}`;
|
|
1804
|
+
* ```
|
|
1805
|
+
*
|
|
1309
1806
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
1310
1807
|
*/
|
|
1311
|
-
trace(...
|
|
1808
|
+
trace(...args: TaggedTemplateOrMessageArgs): void;
|
|
1312
1809
|
/**
|
|
1313
1810
|
* Sends a log message to the logging library under the fatal log level
|
|
1314
1811
|
*
|
|
1812
|
+
* Supports tagged template syntax:
|
|
1813
|
+
* ```typescript
|
|
1814
|
+
* log.fatal`System crash: ${reason}`;
|
|
1815
|
+
* ```
|
|
1816
|
+
*
|
|
1315
1817
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
1316
1818
|
*/
|
|
1317
|
-
fatal(...
|
|
1819
|
+
fatal(...args: TaggedTemplateOrMessageArgs): void;
|
|
1318
1820
|
/**
|
|
1319
1821
|
* Logs a raw log entry with complete control over all log parameters.
|
|
1320
1822
|
*
|
|
@@ -1328,7 +1830,7 @@ declare class LogLayer$1 implements ILogLayer<LogLayer$1> {
|
|
|
1328
1830
|
*
|
|
1329
1831
|
* @see {@link https://loglayer.dev/logging-api/basic-logging.html | Basic Logging Docs}
|
|
1330
1832
|
*/
|
|
1331
|
-
raw(logEntry:
|
|
1833
|
+
raw<R extends RawLogEntry>(logEntry: R): LogReturnType<ContainsAsyncLazy<NonNullable<R["metadata"]>>>;
|
|
1332
1834
|
/**
|
|
1333
1835
|
* All logging inputs are dropped and stops sending logs to the logging library.
|
|
1334
1836
|
*
|
|
@@ -1408,80 +1910,147 @@ declare class LogLayer$1 implements ILogLayer<LogLayer$1> {
|
|
|
1408
1910
|
* @see {@link https://loglayer.dev/logging-api/transport-management.html | Transport Management Docs}
|
|
1409
1911
|
*/
|
|
1410
1912
|
getLoggerInstance<Logger>(id: string): Logger | undefined;
|
|
1913
|
+
/**
|
|
1914
|
+
* Parses the LOGLAYER_GROUPS environment variable and overrides
|
|
1915
|
+
* _activeGroups and group levels accordingly.
|
|
1916
|
+
* Format: "name,name" or "name:level,name:level"
|
|
1917
|
+
*/
|
|
1918
|
+
private _parseEnvGroups;
|
|
1919
|
+
/**
|
|
1920
|
+
* Merges per-log groups (from LogBuilder) with logger-level assigned groups.
|
|
1921
|
+
*/
|
|
1922
|
+
private _mergeGroups;
|
|
1923
|
+
/**
|
|
1924
|
+
* Applies ungrouped routing rules for a transport.
|
|
1925
|
+
*/
|
|
1926
|
+
private _applyUngroupedRules;
|
|
1927
|
+
/**
|
|
1928
|
+
* Determines whether a transport should receive a log entry based on group routing rules.
|
|
1929
|
+
*/
|
|
1930
|
+
private _shouldTransportReceiveLog;
|
|
1411
1931
|
_formatMessage(messages?: MessageDataType[]): void;
|
|
1412
1932
|
_formatLog({
|
|
1413
1933
|
logLevel,
|
|
1414
1934
|
params,
|
|
1415
1935
|
metadata,
|
|
1416
1936
|
err,
|
|
1417
|
-
context
|
|
1418
|
-
|
|
1937
|
+
context,
|
|
1938
|
+
groups
|
|
1939
|
+
}: FormatLogParams): void | Promise<void>;
|
|
1940
|
+
/**
|
|
1941
|
+
* Resolves any Promise values in metadata (from async lazy callbacks)
|
|
1942
|
+
* and then processes the log entry. Context is already fully resolved.
|
|
1943
|
+
*/
|
|
1944
|
+
private _resolveAsyncAndProcess;
|
|
1945
|
+
/**
|
|
1946
|
+
* Logs error entries for lazy evaluation failures.
|
|
1947
|
+
* Calls _processLog directly to bypass lazy evaluation and prevent recursion.
|
|
1948
|
+
*/
|
|
1949
|
+
private _logLazyEvalErrors;
|
|
1950
|
+
/**
|
|
1951
|
+
* Logs error entries for async lazy values found in context.
|
|
1952
|
+
* Async lazy values are only supported in metadata, not context.
|
|
1953
|
+
*/
|
|
1954
|
+
private _logAsyncLazyContextErrors;
|
|
1955
|
+
/**
|
|
1956
|
+
* Processes a log entry after lazy values have been fully resolved.
|
|
1957
|
+
* Handles data assembly, plugins, and transport dispatch.
|
|
1958
|
+
*/
|
|
1959
|
+
private _processLog;
|
|
1419
1960
|
} //#endregion
|
|
1420
1961
|
//#region src/LogBuilder.d.ts
|
|
1421
1962
|
/**
|
|
1422
1963
|
* A class that contains methods to specify log metadata and an error and assembles
|
|
1423
1964
|
* it to form a data object that can be passed into the transport.
|
|
1424
1965
|
*/
|
|
1425
|
-
declare class LogBuilder implements ILogBuilder<LogBuilder> {
|
|
1966
|
+
declare class LogBuilder implements ILogBuilder<LogBuilder, boolean> {
|
|
1426
1967
|
private err;
|
|
1427
1968
|
private metadata;
|
|
1428
1969
|
private structuredLogger;
|
|
1429
1970
|
private hasMetadata;
|
|
1430
1971
|
private pluginManager;
|
|
1972
|
+
private _groups;
|
|
1431
1973
|
constructor(structuredLogger: LogLayer$1);
|
|
1432
1974
|
/**
|
|
1433
1975
|
* Specifies metadata to include with the log message
|
|
1434
1976
|
*
|
|
1435
1977
|
* @see {@link https://loglayer.dev/logging-api/metadata.html | Metadata Docs}
|
|
1436
1978
|
*/
|
|
1437
|
-
withMetadata(metadata?: LogLayerMetadata):
|
|
1979
|
+
withMetadata(metadata?: LogLayerMetadata): any;
|
|
1438
1980
|
/**
|
|
1439
1981
|
* Specifies an Error to include with the log message
|
|
1440
1982
|
*
|
|
1441
1983
|
* @see {@link https://loglayer.dev/logging-api/error-handling.html | Error Handling Docs}
|
|
1442
1984
|
*/
|
|
1443
|
-
withError(error: any):
|
|
1985
|
+
withError(error: any): any;
|
|
1986
|
+
/**
|
|
1987
|
+
* Tags this log entry with one or more groups for routing.
|
|
1988
|
+
*
|
|
1989
|
+
* @see {@link https://loglayer.dev/logging-api/groups.html | Groups Docs}
|
|
1990
|
+
*/
|
|
1991
|
+
withGroup(group: string | string[]): any;
|
|
1444
1992
|
/**
|
|
1445
1993
|
* Sends a log message to the logging library under an info log level.
|
|
1994
|
+
*
|
|
1995
|
+
* Supports tagged template syntax:
|
|
1996
|
+
* ```typescript
|
|
1997
|
+
* log.withMetadata({ userId }).info`User ${userId} logged in`;
|
|
1998
|
+
* ```
|
|
1446
1999
|
*/
|
|
1447
|
-
info(...
|
|
2000
|
+
info(...args: TaggedTemplateOrMessageArgs): void | Promise<void>;
|
|
1448
2001
|
/**
|
|
1449
2002
|
* Sends a log message to the logging library under the warn log level
|
|
2003
|
+
*
|
|
2004
|
+
* Supports tagged template syntax:
|
|
2005
|
+
* ```typescript
|
|
2006
|
+
* log.withMetadata({ requestId }).warn`Request ${requestId} timed out`;
|
|
2007
|
+
* ```
|
|
1450
2008
|
*/
|
|
1451
|
-
warn(...
|
|
2009
|
+
warn(...args: TaggedTemplateOrMessageArgs): void | Promise<void>;
|
|
1452
2010
|
/**
|
|
1453
2011
|
* Sends a log message to the logging library under the error log level
|
|
2012
|
+
*
|
|
2013
|
+
* Supports tagged template syntax:
|
|
2014
|
+
* ```typescript
|
|
2015
|
+
* log.withError(err).error`Failed to process ${taskId}`;
|
|
2016
|
+
* ```
|
|
1454
2017
|
*/
|
|
1455
|
-
error(...
|
|
2018
|
+
error(...args: TaggedTemplateOrMessageArgs): void | Promise<void>;
|
|
1456
2019
|
/**
|
|
1457
2020
|
* Sends a log message to the logging library under the debug log level
|
|
1458
2021
|
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
2022
|
+
* Supports tagged template syntax:
|
|
2023
|
+
* ```typescript
|
|
2024
|
+
* log.withMetadata({ cacheKey }).debug`Cache hit for ${cacheKey}`;
|
|
2025
|
+
* ```
|
|
1461
2026
|
*/
|
|
1462
|
-
debug(...
|
|
2027
|
+
debug(...args: TaggedTemplateOrMessageArgs): void | Promise<void>;
|
|
1463
2028
|
/**
|
|
1464
2029
|
* Sends a log message to the logging library under the trace log level
|
|
1465
2030
|
*
|
|
1466
|
-
*
|
|
1467
|
-
*
|
|
2031
|
+
* Supports tagged template syntax:
|
|
2032
|
+
* ```typescript
|
|
2033
|
+
* log.withMetadata({ functionName }).trace`Entering ${functionName}`;
|
|
2034
|
+
* ```
|
|
1468
2035
|
*/
|
|
1469
|
-
trace(...
|
|
2036
|
+
trace(...args: TaggedTemplateOrMessageArgs): void | Promise<void>;
|
|
1470
2037
|
/**
|
|
1471
2038
|
* Sends a log message to the logging library under the fatal log level
|
|
1472
2039
|
*
|
|
1473
|
-
*
|
|
1474
|
-
*
|
|
2040
|
+
* Supports tagged template syntax:
|
|
2041
|
+
* ```typescript
|
|
2042
|
+
* log.withError(err).fatal`System crash: ${reason}`;
|
|
2043
|
+
* ```
|
|
1475
2044
|
*/
|
|
1476
|
-
fatal(...
|
|
2045
|
+
fatal(...args: TaggedTemplateOrMessageArgs): void | Promise<void>;
|
|
1477
2046
|
/**
|
|
1478
2047
|
* All logging inputs are dropped and stops sending logs to the logging library.
|
|
1479
2048
|
*/
|
|
1480
|
-
disableLogging():
|
|
2049
|
+
disableLogging(): any;
|
|
1481
2050
|
/**
|
|
1482
2051
|
* Enable sending logs to the logging library.
|
|
1483
2052
|
*/
|
|
1484
|
-
enableLogging():
|
|
2053
|
+
enableLogging(): any;
|
|
1485
2054
|
private formatLog;
|
|
1486
2055
|
} //#endregion
|
|
1487
2056
|
//#region src/mixins.d.ts
|