unnbound-logger-sdk 2.0.8 → 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
@@ -89,6 +89,11 @@ class UnnboundLogger {
89
89
  // Axios response interceptor (should be used separately)
90
90
  this.axiosResponseInterceptor = {
91
91
  onFulfilled: (response) => {
92
+ // Check if the URL should be ignored
93
+ const url = `${response.config?.baseURL || ''}${response.config?.url}`;
94
+ if (url && this.shouldIgnorePath(url, this.ignoreAxiosTraceRoutes)) {
95
+ return response;
96
+ }
92
97
  // Calculate duration
93
98
  const startTime = response.config.metadata?.startTime || Date.now();
94
99
  const requestId = response.config.metadata?.requestId;
@@ -121,6 +126,11 @@ class UnnboundLogger {
121
126
  return response;
122
127
  },
123
128
  onRejected: (error) => {
129
+ // Check if the URL should be ignored
130
+ const url = `${error.config?.baseURL || ''}${error.config?.url}`;
131
+ if (url && this.shouldIgnorePath(url, this.ignoreAxiosTraceRoutes)) {
132
+ return Promise.reject(error);
133
+ }
124
134
  // Calculate duration for error responses
125
135
  const startTime = error.config?.metadata?.startTime || Date.now();
126
136
  const requestId = error.config?.metadata?.requestId;
@@ -217,6 +227,8 @@ class UnnboundLogger {
217
227
  const requestId = options.requestId || (0, uuid_1.v4)();
218
228
  let logEntry;
219
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;
220
232
  const baseEntry = {
221
233
  logId,
222
234
  type: 'general',
@@ -236,23 +248,23 @@ class UnnboundLogger {
236
248
  ...baseEntry,
237
249
  message: message.name,
238
250
  error,
239
- ...restOptions,
251
+ ...(hasRestOptions && { data: restOptions }),
240
252
  };
241
253
  }
242
254
  else if (typeof message === 'string') {
243
255
  logEntry = {
244
256
  ...baseEntry,
245
257
  message,
246
- ...restOptions,
258
+ ...(hasRestOptions && { data: restOptions }),
247
259
  };
248
260
  }
249
261
  else {
250
- // 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;
251
264
  logEntry = {
252
265
  ...baseEntry,
253
- ...message,
254
- message: message.message || 'Structured log data',
255
- ...restOptions,
266
+ message: 'Structured log data',
267
+ data: hasRestOptions ? { ...messageObj, ...restOptions } : messageObj,
256
268
  };
257
269
  }
258
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.8",
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",