@adobe/spacecat-shared-utils 1.85.0 → 1.85.1
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 +7 -0
- package/package.json +1 -1
- package/src/log-wrapper.js +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.85.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.85.0...@adobe/spacecat-shared-utils-v1.85.1) (2025-12-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Structured (JSON) for Logging should be JSON string ([#1237](https://github.com/adobe/spacecat-shared/issues/1237)) ([cfcee6e](https://github.com/adobe/spacecat-shared/commit/cfcee6e4315aa518c52e4ca50b99b0cb762f5a61))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-utils-v1.85.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.84.0...@adobe/spacecat-shared-utils-v1.85.0) (2025-12-11)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/log-wrapper.js
CHANGED
|
@@ -27,11 +27,13 @@ function isPlainObject(value) {
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* A higher-order function that wraps a given function and enhances logging by converting
|
|
30
|
-
* all logs to JSON format and appending `jobId`
|
|
30
|
+
* all logs to JSON format and appending `severity`, `jobId`and `traceId`
|
|
31
|
+
* to log messages when available.
|
|
31
32
|
*
|
|
32
33
|
* All log messages are automatically converted to structured JSON format:
|
|
33
|
-
* - String messages become: { message: "...", jobId: "...", traceId: "..." }
|
|
34
|
-
* - Object messages are merged with:
|
|
34
|
+
* - String messages become: { severity: "info", message: "...", jobId: "...", traceId: "..." }
|
|
35
|
+
* - Object messages are merged with:
|
|
36
|
+
* { severity: "info", ...yourObject, jobId: "...", traceId: "..." }
|
|
35
37
|
*
|
|
36
38
|
* @param {function} fn - The original function to be wrapped
|
|
37
39
|
* @returns {function(object, object): Promise<Response>} - A wrapped function with JSON logging
|
|
@@ -63,12 +65,13 @@ export function logWrapper(fn) {
|
|
|
63
65
|
accumulator[level] = (...args) => {
|
|
64
66
|
// If first argument is a plain object, merge with markers
|
|
65
67
|
if (args.length > 0 && isPlainObject(args[0])) {
|
|
66
|
-
return log[level]({ ...markers, ...args[0] });
|
|
68
|
+
return log[level](JSON.stringify({ severity: level, ...markers, ...args[0] }));
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
// If first argument is a string, convert to structured format
|
|
70
72
|
if (args.length > 0 && typeof args[0] === 'string') {
|
|
71
73
|
const logObject = {
|
|
74
|
+
severity: level,
|
|
72
75
|
...markers,
|
|
73
76
|
message: args[0],
|
|
74
77
|
};
|
|
@@ -87,11 +90,11 @@ export function logWrapper(fn) {
|
|
|
87
90
|
logObject.data = args.slice(1);
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
return log[level](logObject);
|
|
93
|
+
return log[level](JSON.stringify(logObject));
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
// For other types (arrays, primitives, Error objects), wrap in object
|
|
94
|
-
return log[level]({ ...markers, data: args });
|
|
97
|
+
return log[level](JSON.stringify({ severity: level, ...markers, data: args }));
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
100
|
return accumulator;
|