b2b-platform-utils 1.1.19 → 1.1.20
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/logger.js +28 -5
- package/package.json +1 -1
package/logger.js
CHANGED
|
@@ -94,16 +94,39 @@ function safeStringify(value) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
97
|
+
* Flexible debug logger supporting (msg), (obj), (msg, obj), (obj, msg).
|
|
98
|
+
*
|
|
99
|
+
* @param {...any} args - Message and/or data.
|
|
99
100
|
*/
|
|
100
|
-
function debug(
|
|
101
|
+
function debug(...args) {
|
|
101
102
|
const { isProd } = resolveContext();
|
|
102
|
-
|
|
103
|
+
|
|
104
|
+
let message = null;
|
|
105
|
+
let data = null;
|
|
106
|
+
|
|
107
|
+
// Extract pieces from args
|
|
108
|
+
for (const arg of args) {
|
|
109
|
+
if (typeof arg === 'string' && !message) {
|
|
110
|
+
message = arg;
|
|
111
|
+
} else if (typeof arg === 'object' && arg !== null && !data) {
|
|
112
|
+
data = arg;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Normalize payload
|
|
117
|
+
const payload = {
|
|
118
|
+
level: 'debug',
|
|
119
|
+
message: message || 'debug log',
|
|
120
|
+
data: data || null,
|
|
121
|
+
timestamp: Date.now()
|
|
122
|
+
};
|
|
103
123
|
|
|
104
124
|
if (isProd) {
|
|
105
|
-
|
|
125
|
+
// Structured JSON for production
|
|
126
|
+
asyncWrite('stdout', serializeJSON('debug', payload.message, { data: payload.data }));
|
|
106
127
|
} else {
|
|
128
|
+
// Pretty colored dev-mode output
|
|
129
|
+
const text = safeStringify(payload);
|
|
107
130
|
asyncWrite('stdout', colorize('\x1b[35m', '🐛', text, 'DEBUG'));
|
|
108
131
|
}
|
|
109
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "b2b-platform-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.20",
|
|
4
4
|
"description": "Shared utilities for Node.js microservices: errors map, local cache, logger, numbers, dates, filesystem, media optimization, paginator, slugger, crypto wrapper, sanitize HTML, sorting.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"license": "KingSizer",
|