unnbound-logger-sdk 2.0.9 → 2.0.10

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 CHANGED
@@ -22,24 +22,27 @@ logger.warn('Resource usage high');
22
22
  logger.error(new Error('Database connection failed'));
23
23
  logger.debug('Debug information');
24
24
 
25
- // Log with object messages
25
+ // Log with object messages (wrapped in 'data' field)
26
26
  logger.info({
27
27
  event: 'user_login',
28
28
  userId: '123',
29
29
  timestamp: new Date().toISOString()
30
30
  });
31
+ // Results in: { "data": { "event": "user_login", "userId": "123", "timestamp": "..." }, "message": "Structured log data", ... }
31
32
 
32
- // Log with both string message and metadata
33
+ // Log with both string message and metadata (metadata added to top level)
33
34
  logger.info('User logged in', {
34
35
  userId: '123',
35
36
  timestamp: new Date().toISOString()
36
37
  });
38
+ // Results in: { "userId": "123", "timestamp": "...", "message": "User logged in", ... }
37
39
 
38
40
  // Log with object message and additional metadata
39
41
  logger.info(
40
42
  { event: 'user_login', userId: '123' },
41
43
  { timestamp: new Date().toISOString() }
42
44
  );
45
+ // Results in: { "data": { "event": "user_login", "userId": "123" }, "timestamp": "...", "message": "Structured log data", ... }
43
46
  ```
44
47
 
45
48
  ## Log Format
@@ -109,6 +112,43 @@ If the environment variables are not set, the fields will be empty strings. Thes
109
112
  - **Correlating issues**: Link problems to specific workflows and releases
110
113
  - **Monitoring**: Track health and performance across workflows and deployments
111
114
 
115
+ ## Object Logging Behavior
116
+
117
+ The logger handles different message types differently to ensure consistent structure in your logs:
118
+
119
+ ### String Messages with Metadata
120
+ When you pass a string message with additional metadata, the metadata is wrapped in a `data` field:
121
+
122
+ ```typescript
123
+ logger.info('User action completed', { userId: '123', action: 'login' });
124
+ // Result: { "message": "User action completed", "data": { "userId": "123", "action": "login" }, ... }
125
+ ```
126
+
127
+ ### Object Messages
128
+ When you pass an object as the message, it gets wrapped in a `data` field to prevent unknown properties from polluting the top level:
129
+
130
+ ```typescript
131
+ logger.info({ userId: '123', action: 'login', timestamp: '2025-01-01T12:00:00Z' });
132
+ // Result: { "message": "Structured log data", "data": { "userId": "123", "action": "login", "timestamp": "2025-01-01T12:00:00Z" }, ... }
133
+ ```
134
+
135
+ If the object contains a `message` property, it remains in the `data` object and doesn't affect the top-level message:
136
+
137
+ ```typescript
138
+ logger.info({ message: 'Custom message', userId: '123' });
139
+ // Result: { "message": "Structured log data", "data": { "message": "Custom message", "userId": "123" }, ... }
140
+ ```
141
+
142
+ ### Error Objects
143
+ Error objects are handled specially and include serialized error information:
144
+
145
+ ```typescript
146
+ logger.error(new Error('Something went wrong'));
147
+ // Result: { "message": "Error", "error": { "name": "Error", "message": "Something went wrong", "stack": "..." }, ... }
148
+ ```
149
+
150
+ This structure ensures your UI can reliably access all object data through the `data` field without worrying about unknown properties at the top level. Whether you pass an object as the message or as metadata, it will always be contained within the `data` field.
151
+
112
152
  ## HTTP Request/Response Logging
113
153
 
114
154
  ```typescript
@@ -227,6 +227,8 @@ class UnnboundLogger {
227
227
  const requestId = options.requestId || (0, uuid_1.v4)();
228
228
  let logEntry;
229
229
  const { traceId: optionTraceId, requestId: optionRequestId, level: optionLevel, ...restOptions } = options;
230
+ // If restOptions has any properties, we'll add them to data later
231
+ const hasRestOptions = Object.keys(restOptions).length > 0;
230
232
  const baseEntry = {
231
233
  logId,
232
234
  type: 'general',
@@ -246,23 +248,23 @@ class UnnboundLogger {
246
248
  ...baseEntry,
247
249
  message: message.name,
248
250
  error,
249
- ...restOptions,
251
+ ...(hasRestOptions && { data: restOptions }),
250
252
  };
251
253
  }
252
254
  else if (typeof message === 'string') {
253
255
  logEntry = {
254
256
  ...baseEntry,
255
257
  message,
256
- ...restOptions,
258
+ ...(hasRestOptions && { data: restOptions }),
257
259
  };
258
260
  }
259
261
  else {
260
- // If message is an object, it's part of the log entry
262
+ // If message is an object, wrap it in a 'data' key
263
+ const messageObj = message;
261
264
  logEntry = {
262
265
  ...baseEntry,
263
- ...message,
264
- message: message.message || 'Structured log data',
265
- ...restOptions,
266
+ message: 'Structured log data',
267
+ data: hasRestOptions ? { ...messageObj, ...restOptions } : messageObj,
266
268
  };
267
269
  }
268
270
  // Separate the message from the log data and explicitly exclude any level field
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unnbound-logger-sdk",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",