b2b-platform-utils 1.1.19 → 1.1.21

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.
Files changed (2) hide show
  1. package/logger.js +27 -5
  2. package/package.json +1 -1
package/logger.js CHANGED
@@ -94,16 +94,38 @@ function safeStringify(value) {
94
94
  }
95
95
 
96
96
  /**
97
- * Print a debug payload (object) as magenta JSON or structured JSON in prod.
98
- * @param {any} data
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(data) {
101
+ function debug(...args) {
101
102
  const { isProd } = resolveContext();
102
- const text = safeStringify(data);
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
+ message: message || 'debug log',
119
+ data: data || null,
120
+ timestamp: new Date().toISOString()
121
+ };
103
122
 
104
123
  if (isProd) {
105
- asyncWrite('stdout', serializeJSON('debug', 'debug payload', { data }));
124
+ // Structured JSON for production
125
+ asyncWrite('stdout', serializeJSON('debug', payload.message, { data: payload.data }));
106
126
  } else {
127
+ // Pretty colored dev-mode output
128
+ const text = safeStringify(payload);
107
129
  asyncWrite('stdout', colorize('\x1b[35m', '🐛', text, 'DEBUG'));
108
130
  }
109
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "b2b-platform-utils",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
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",