unnbound-logger-sdk 2.0.5 → 2.0.7

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
@@ -357,12 +357,12 @@ new UnnboundLogger(options?: LoggerOptions)
357
357
 
358
358
  #### Methods
359
359
 
360
- - `log(level: LogLevel, message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void`
361
- - `error(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void`
362
- - `warn(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void`
363
- - `info(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void`
364
- - `debug(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void`
365
- - `httpRequest(req: Request, options?: HttpRequestLogOptions): string`
366
- - `httpResponse(res: Response, req: Request, options: HttpResponseLogOptions): void`
367
- - `sftpTransaction(operation: SftpOperation, options?: SftpTransactionLogOptions): void`
368
- - `dbQueryTransaction(query: DbQuery, options?: DbQueryTransactionLogOptions): void`
360
+ - `log(level: LogLevel, message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log`
361
+ - `error(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log`
362
+ - `warn(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log`
363
+ - `info(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log`
364
+ - `debug(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log`
365
+ - `httpRequest(req: Request, options?: HttpRequestLogOptions): HttpRequestLog`
366
+ - `httpResponse(res: Response, req: Request, options: HttpResponseLogOptions): HttpResponseLog`
367
+ - `sftpTransaction(operation: SftpOperation, options?: SftpTransactionLogOptions): SftpTransactionLog`
368
+ - `dbQueryTransaction(query: DbQuery, options?: DbQueryTransactionLogOptions): DbQueryTransactionLog`
@@ -1,4 +1,4 @@
1
- import { LogLevel, LoggerOptions, GeneralLogOptions, HttpRequestLogOptions, HttpResponseLogOptions, SftpTransactionLogOptions, DbQueryTransactionLogOptions } from './types';
1
+ import { LogLevel, LoggerOptions, GeneralLogOptions, HttpRequestLogOptions, HttpResponseLogOptions, SftpTransactionLogOptions, DbQueryTransactionLogOptions, Log, HttpRequestLog, HttpResponseLog, SftpTransactionLog, DbQueryTransactionLog } from './types';
2
2
  import { Request, Response, NextFunction } from 'express';
3
3
  import { InternalAxiosRequestConfig } from 'axios';
4
4
  declare module 'axios' {
@@ -37,31 +37,31 @@ export declare class UnnboundLogger {
37
37
  * @param message - Log message
38
38
  * @param options - Additional logging options
39
39
  */
40
- log(level: LogLevel, message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void;
40
+ log(level: LogLevel, message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log;
41
41
  /**
42
42
  * Logs an error message
43
43
  * @param message - Error message or object
44
44
  * @param options - Additional logging options
45
45
  */
46
- error(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void;
46
+ error(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log;
47
47
  /**
48
48
  * Logs a warning message
49
49
  * @param message - Warning message
50
50
  * @param options - Additional logging options
51
51
  */
52
- warn(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void;
52
+ warn(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log;
53
53
  /**
54
54
  * Logs an info message
55
55
  * @param message - Info message
56
56
  * @param options - Additional logging options
57
57
  */
58
- info(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void;
58
+ info(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log;
59
59
  /**
60
60
  * Logs a debug message
61
61
  * @param message - Debug message
62
62
  * @param options - Additional logging options
63
63
  */
64
- debug(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): void;
64
+ debug(message: string | Error | Record<string, unknown>, options?: GeneralLogOptions): Log;
65
65
  /**
66
66
  * Constructs the full URL from request information
67
67
  * @param req - Express request object
@@ -74,14 +74,14 @@ export declare class UnnboundLogger {
74
74
  * @param options - Additional logging options
75
75
  * @returns The request ID for correlating with the response
76
76
  */
77
- httpRequest(req: Request, options?: HttpRequestLogOptions): string;
77
+ httpRequest(req: Request, options?: HttpRequestLogOptions): HttpRequestLog;
78
78
  /**
79
79
  * Logs an HTTP response
80
80
  * @param res - Express response object
81
81
  * @param req - Express request object
82
82
  * @param options - Additional logging options
83
83
  */
84
- httpResponse(res: Response, req: Request, options?: HttpResponseLogOptions): void;
84
+ httpResponse(res: Response, req: Request, options?: HttpResponseLogOptions): HttpResponseLog;
85
85
  /**
86
86
  * Logs an SFTP transaction
87
87
  * @param operation - SFTP operation details
@@ -96,7 +96,7 @@ export declare class UnnboundLogger {
96
96
  bytesTransferred?: number;
97
97
  filesListed?: number;
98
98
  sourcePath?: string;
99
- }, options?: SftpTransactionLogOptions): void;
99
+ }, options?: SftpTransactionLogOptions): SftpTransactionLog;
100
100
  /**
101
101
  * Logs a database query transaction
102
102
  * @param query - Database query details
@@ -109,7 +109,7 @@ export declare class UnnboundLogger {
109
109
  status: 'success' | 'failure';
110
110
  rowsReturned?: number;
111
111
  rowsAffected?: number;
112
- }, options?: DbQueryTransactionLogOptions): void;
112
+ }, options?: DbQueryTransactionLogOptions): DbQueryTransactionLog;
113
113
  traceMiddleware: (req: Request, res: Response, next: NextFunction) => void;
114
114
  axiosTraceMiddleware: {
115
115
  onFulfilled: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
@@ -32,7 +32,7 @@ class UnnboundLogger {
32
32
  res.setHeader(this.traceHeaderKey, traceId);
33
33
  trace_context_1.traceContext.run(traceId, () => {
34
34
  // Log the incoming request
35
- const requestId = this.httpRequest(req, { traceId });
35
+ const reqLog = this.httpRequest(req, { traceId });
36
36
  // Capture response body for logging
37
37
  const originalSend = res.send;
38
38
  res.send = function (body) {
@@ -41,7 +41,7 @@ class UnnboundLogger {
41
41
  };
42
42
  // Log the response when it finishes
43
43
  res.on('finish', () => {
44
- this.httpResponse(res, req, { requestId, traceId });
44
+ this.httpResponse(res, req, { requestId: reqLog.requestId, traceId });
45
45
  });
46
46
  next();
47
47
  });
@@ -178,6 +178,7 @@ class UnnboundLogger {
178
178
  level: 'info',
179
179
  base: {}, // Disable all default base fields (pid, hostname)
180
180
  timestamp: false, // Let CloudWatch handle timestamps
181
+ messageKey: 'messages', // Change message field from 'msg' to 'messages'
181
182
  formatters: {
182
183
  level: (label) => {
183
184
  return { level: label };
@@ -213,7 +214,7 @@ class UnnboundLogger {
213
214
  const traceId = options.traceId || trace_context_1.traceContext.getTraceId() || (0, uuid_1.v4)();
214
215
  const requestId = options.requestId || (0, uuid_1.v4)();
215
216
  let logEntry;
216
- const { traceId: optionTraceId, requestId: optionRequestId, ...restOptions } = options;
217
+ const { traceId: optionTraceId, requestId: optionRequestId, level: optionLevel, ...restOptions } = options;
217
218
  const baseEntry = {
218
219
  logId,
219
220
  type: 'general',
@@ -251,7 +252,10 @@ class UnnboundLogger {
251
252
  ...restOptions,
252
253
  };
253
254
  }
254
- this.logger[level](logEntry);
255
+ // Separate the message from the log data and explicitly exclude any level field
256
+ const { message: logMessage, level: excludedLevel, ...logData } = logEntry;
257
+ this.logger[level](logData, logMessage);
258
+ return logEntry;
255
259
  }
256
260
  /**
257
261
  * Logs an error message
@@ -259,7 +263,7 @@ class UnnboundLogger {
259
263
  * @param options - Additional logging options
260
264
  */
261
265
  error(message, options = {}) {
262
- this.log('error', message, options);
266
+ return this.log('error', message, options);
263
267
  }
264
268
  /**
265
269
  * Logs a warning message
@@ -267,7 +271,7 @@ class UnnboundLogger {
267
271
  * @param options - Additional logging options
268
272
  */
269
273
  warn(message, options = {}) {
270
- this.log('warn', message, options);
274
+ return this.log('warn', message, options);
271
275
  }
272
276
  /**
273
277
  * Logs an info message
@@ -275,7 +279,7 @@ class UnnboundLogger {
275
279
  * @param options - Additional logging options
276
280
  */
277
281
  info(message, options = {}) {
278
- this.log('info', message, options);
282
+ return this.log('info', message, options);
279
283
  }
280
284
  /**
281
285
  * Logs a debug message
@@ -283,7 +287,7 @@ class UnnboundLogger {
283
287
  * @param options - Additional logging options
284
288
  */
285
289
  debug(message, options = {}) {
286
- this.log('debug', message, options);
290
+ return this.log('debug', message, options);
287
291
  }
288
292
  /**
289
293
  * Constructs the full URL from request information
@@ -342,8 +346,8 @@ class UnnboundLogger {
342
346
  body: (0, logger_utils_1.safeJsonParse)(req.body),
343
347
  },
344
348
  };
345
- this.log(options.level || 'info', logEntry);
346
- return requestId;
349
+ const result = this.log(options.level || 'info', logEntry);
350
+ return result;
347
351
  }
348
352
  /**
349
353
  * Logs an HTTP response
@@ -386,7 +390,8 @@ class UnnboundLogger {
386
390
  body: (0, logger_utils_1.safeJsonParse)(res.locals.body),
387
391
  },
388
392
  };
389
- this.log(level, logEntry);
393
+ const result = this.log(level, logEntry);
394
+ return result;
390
395
  }
391
396
  /**
392
397
  * Logs an SFTP transaction
@@ -410,7 +415,8 @@ class UnnboundLogger {
410
415
  duration,
411
416
  sftp: operation,
412
417
  };
413
- this.log(level, logEntry);
418
+ const result = this.log(level, logEntry);
419
+ return result;
414
420
  }
415
421
  /**
416
422
  * Logs a database query transaction
@@ -434,7 +440,8 @@ class UnnboundLogger {
434
440
  duration,
435
441
  db: query,
436
442
  };
437
- this.log(level, logEntry);
443
+ const result = this.log(level, logEntry);
444
+ return result;
438
445
  }
439
446
  }
440
447
  exports.UnnboundLogger = UnnboundLogger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unnbound-logger-sdk",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
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",