@loglayer/mixin-wide-events 1.1.0 → 1.2.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/README.md +15 -5
- package/dist/index.cjs +7 -3
- package/dist/index.d.cts +11 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.mjs +7 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# wide-events mixin for LogLayer
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@loglayer/mixin-wide-events)
|
|
4
|
+
[](https://www.npmjs.com/package/@loglayer/mixin-wide-events)
|
|
5
5
|
[](http://www.typescriptlang.org/)
|
|
6
6
|
|
|
7
|
-
Adds wide event logging functionality to LogLayer
|
|
7
|
+
Adds wide event logging functionality to the [LogLayer](https://loglayer.dev) logging library, enabling comprehensive, self-contained log entries that capture an entire operation's context using Node.js `AsyncLocalStorage`.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The mixin provides methods to accumulate data across async boundaries and emit it as a single log entry, along with built-in sampling support.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install loglayer @loglayer/mixin-wide-events
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Documentation
|
|
18
|
+
|
|
19
|
+
For more details, visit [https://loglayer.dev/mixins/wide-events](https://loglayer.dev/mixins/wide-events).
|
package/dist/index.cjs
CHANGED
|
@@ -151,13 +151,13 @@ function createWideEventMixin(options) {
|
|
|
151
151
|
const contextTrackerPlugin = {
|
|
152
152
|
id: `@loglayer/wide-events-context-tracker-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
153
153
|
onBeforeDataOut: (params) => {
|
|
154
|
-
if (!includeContext) return params;
|
|
154
|
+
if (!includeContext) return params.data;
|
|
155
155
|
const store = asyncContext.getStore();
|
|
156
156
|
if (store && params.context && Object.keys(params.context).length > 0) {
|
|
157
157
|
if (!store._llContext) store._llContext = {};
|
|
158
158
|
Object.assign(store._llContext, params.context);
|
|
159
159
|
}
|
|
160
|
-
return params;
|
|
160
|
+
return params.data;
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
/**
|
|
@@ -242,7 +242,11 @@ function createWideEventMixin(options) {
|
|
|
242
242
|
if (!runRateSampling(level, samplingConfig.strategy, samplingConfig.rate, samplingConfig.perLevel) || !callbackOk) return;
|
|
243
243
|
} catch {}
|
|
244
244
|
const metadataToEmit = wideEventField ? { [wideEventField]: wideEventData } : wideEventData;
|
|
245
|
-
self.
|
|
245
|
+
self.raw({
|
|
246
|
+
logLevel: level,
|
|
247
|
+
messages: [config.message],
|
|
248
|
+
rootData: metadataToEmit
|
|
249
|
+
});
|
|
246
250
|
}
|
|
247
251
|
return {
|
|
248
252
|
mixinsToAdd: [{
|
package/dist/index.d.cts
CHANGED
|
@@ -445,6 +445,15 @@ interface RawLogEntry {
|
|
|
445
445
|
* Metadata to include with the log entry.
|
|
446
446
|
*/
|
|
447
447
|
metadata?: LogLayerMetadata;
|
|
448
|
+
/**
|
|
449
|
+
* Data to spread directly at the root level of the log entry.
|
|
450
|
+
*
|
|
451
|
+
* Unlike `metadata`, this bypasses `metadataFieldName` / `contextFieldName`
|
|
452
|
+
* nesting and is always flattened at the root of the emitted log object.
|
|
453
|
+
*
|
|
454
|
+
* Note: Unlike `metadata`, `rootData` does not support lazy evaluation.
|
|
455
|
+
*/
|
|
456
|
+
rootData?: LogLayerMetadata;
|
|
448
457
|
/**
|
|
449
458
|
* Error object to include with the log entry.
|
|
450
459
|
*/
|
|
@@ -1529,6 +1538,7 @@ interface FormatLogParams {
|
|
|
1529
1538
|
logLevel: LogLevelType;
|
|
1530
1539
|
params?: any[];
|
|
1531
1540
|
metadata?: LogLayerMetadata | null;
|
|
1541
|
+
rootData?: LogLayerMetadata | null;
|
|
1532
1542
|
err?: any;
|
|
1533
1543
|
context?: LogLayerContext | null;
|
|
1534
1544
|
groups?: string[] | null;
|
|
@@ -1933,6 +1943,7 @@ declare class LogLayer implements ILogLayer<LogLayer> {
|
|
|
1933
1943
|
logLevel,
|
|
1934
1944
|
params,
|
|
1935
1945
|
metadata,
|
|
1946
|
+
rootData,
|
|
1936
1947
|
err,
|
|
1937
1948
|
context,
|
|
1938
1949
|
groups
|
package/dist/index.d.mts
CHANGED
|
@@ -445,6 +445,15 @@ interface RawLogEntry {
|
|
|
445
445
|
* Metadata to include with the log entry.
|
|
446
446
|
*/
|
|
447
447
|
metadata?: LogLayerMetadata;
|
|
448
|
+
/**
|
|
449
|
+
* Data to spread directly at the root level of the log entry.
|
|
450
|
+
*
|
|
451
|
+
* Unlike `metadata`, this bypasses `metadataFieldName` / `contextFieldName`
|
|
452
|
+
* nesting and is always flattened at the root of the emitted log object.
|
|
453
|
+
*
|
|
454
|
+
* Note: Unlike `metadata`, `rootData` does not support lazy evaluation.
|
|
455
|
+
*/
|
|
456
|
+
rootData?: LogLayerMetadata;
|
|
448
457
|
/**
|
|
449
458
|
* Error object to include with the log entry.
|
|
450
459
|
*/
|
|
@@ -1529,6 +1538,7 @@ interface FormatLogParams {
|
|
|
1529
1538
|
logLevel: LogLevelType;
|
|
1530
1539
|
params?: any[];
|
|
1531
1540
|
metadata?: LogLayerMetadata | null;
|
|
1541
|
+
rootData?: LogLayerMetadata | null;
|
|
1532
1542
|
err?: any;
|
|
1533
1543
|
context?: LogLayerContext | null;
|
|
1534
1544
|
groups?: string[] | null;
|
|
@@ -1933,6 +1943,7 @@ declare class LogLayer implements ILogLayer<LogLayer> {
|
|
|
1933
1943
|
logLevel,
|
|
1934
1944
|
params,
|
|
1935
1945
|
metadata,
|
|
1946
|
+
rootData,
|
|
1936
1947
|
err,
|
|
1937
1948
|
context,
|
|
1938
1949
|
groups
|
package/dist/index.mjs
CHANGED
|
@@ -150,13 +150,13 @@ function createWideEventMixin(options) {
|
|
|
150
150
|
const contextTrackerPlugin = {
|
|
151
151
|
id: `@loglayer/wide-events-context-tracker-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
152
152
|
onBeforeDataOut: (params) => {
|
|
153
|
-
if (!includeContext) return params;
|
|
153
|
+
if (!includeContext) return params.data;
|
|
154
154
|
const store = asyncContext.getStore();
|
|
155
155
|
if (store && params.context && Object.keys(params.context).length > 0) {
|
|
156
156
|
if (!store._llContext) store._llContext = {};
|
|
157
157
|
Object.assign(store._llContext, params.context);
|
|
158
158
|
}
|
|
159
|
-
return params;
|
|
159
|
+
return params.data;
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
/**
|
|
@@ -241,7 +241,11 @@ function createWideEventMixin(options) {
|
|
|
241
241
|
if (!runRateSampling(level, samplingConfig.strategy, samplingConfig.rate, samplingConfig.perLevel) || !callbackOk) return;
|
|
242
242
|
} catch {}
|
|
243
243
|
const metadataToEmit = wideEventField ? { [wideEventField]: wideEventData } : wideEventData;
|
|
244
|
-
self.
|
|
244
|
+
self.raw({
|
|
245
|
+
logLevel: level,
|
|
246
|
+
messages: [config.message],
|
|
247
|
+
rootData: metadataToEmit
|
|
248
|
+
});
|
|
245
249
|
}
|
|
246
250
|
return {
|
|
247
251
|
mixinsToAdd: [{
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loglayer/mixin-wide-events",
|
|
3
3
|
"description": "Adds wide event logging functionality to LogLayer for comprehensive, self-contained log entries.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/node": "25.9.1",
|
|
37
|
-
"tsdown": "0.22.
|
|
37
|
+
"tsdown": "0.22.1",
|
|
38
38
|
"typescript": "6.0.3",
|
|
39
39
|
"vitest": "4.1.7",
|
|
40
|
-
"@
|
|
41
|
-
"loglayer": "
|
|
42
|
-
"
|
|
40
|
+
"@internal/tsconfig": "2.1.0",
|
|
41
|
+
"@loglayer/shared": "4.3.0",
|
|
42
|
+
"loglayer": "9.3.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {},
|
|
45
45
|
"bugs": "https://github.com/loglayer/loglayer/issues",
|