unnbound-logger-sdk 2.0.5 → 2.0.6

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
  });
@@ -213,7 +213,7 @@ class UnnboundLogger {
213
213
  const traceId = options.traceId || trace_context_1.traceContext.getTraceId() || (0, uuid_1.v4)();
214
214
  const requestId = options.requestId || (0, uuid_1.v4)();
215
215
  let logEntry;
216
- const { traceId: optionTraceId, requestId: optionRequestId, ...restOptions } = options;
216
+ const { traceId: optionTraceId, requestId: optionRequestId, level: optionLevel, ...restOptions } = options;
217
217
  const baseEntry = {
218
218
  logId,
219
219
  type: 'general',
@@ -251,7 +251,10 @@ class UnnboundLogger {
251
251
  ...restOptions,
252
252
  };
253
253
  }
254
- this.logger[level](logEntry);
254
+ // Separate the message from the log data and explicitly exclude any level field
255
+ const { message: logMessage, level: excludedLevel, ...logData } = logEntry;
256
+ this.logger[level](logData, logMessage);
257
+ return logEntry;
255
258
  }
256
259
  /**
257
260
  * Logs an error message
@@ -259,7 +262,7 @@ class UnnboundLogger {
259
262
  * @param options - Additional logging options
260
263
  */
261
264
  error(message, options = {}) {
262
- this.log('error', message, options);
265
+ return this.log('error', message, options);
263
266
  }
264
267
  /**
265
268
  * Logs a warning message
@@ -267,7 +270,7 @@ class UnnboundLogger {
267
270
  * @param options - Additional logging options
268
271
  */
269
272
  warn(message, options = {}) {
270
- this.log('warn', message, options);
273
+ return this.log('warn', message, options);
271
274
  }
272
275
  /**
273
276
  * Logs an info message
@@ -275,7 +278,7 @@ class UnnboundLogger {
275
278
  * @param options - Additional logging options
276
279
  */
277
280
  info(message, options = {}) {
278
- this.log('info', message, options);
281
+ return this.log('info', message, options);
279
282
  }
280
283
  /**
281
284
  * Logs a debug message
@@ -283,7 +286,7 @@ class UnnboundLogger {
283
286
  * @param options - Additional logging options
284
287
  */
285
288
  debug(message, options = {}) {
286
- this.log('debug', message, options);
289
+ return this.log('debug', message, options);
287
290
  }
288
291
  /**
289
292
  * Constructs the full URL from request information
@@ -342,8 +345,8 @@ class UnnboundLogger {
342
345
  body: (0, logger_utils_1.safeJsonParse)(req.body),
343
346
  },
344
347
  };
345
- this.log(options.level || 'info', logEntry);
346
- return requestId;
348
+ const result = this.log(options.level || 'info', logEntry);
349
+ return result;
347
350
  }
348
351
  /**
349
352
  * Logs an HTTP response
@@ -386,7 +389,8 @@ class UnnboundLogger {
386
389
  body: (0, logger_utils_1.safeJsonParse)(res.locals.body),
387
390
  },
388
391
  };
389
- this.log(level, logEntry);
392
+ const result = this.log(level, logEntry);
393
+ return result;
390
394
  }
391
395
  /**
392
396
  * Logs an SFTP transaction
@@ -410,7 +414,8 @@ class UnnboundLogger {
410
414
  duration,
411
415
  sftp: operation,
412
416
  };
413
- this.log(level, logEntry);
417
+ const result = this.log(level, logEntry);
418
+ return result;
414
419
  }
415
420
  /**
416
421
  * Logs a database query transaction
@@ -434,7 +439,8 @@ class UnnboundLogger {
434
439
  duration,
435
440
  db: query,
436
441
  };
437
- this.log(level, logEntry);
442
+ const result = this.log(level, logEntry);
443
+ return result;
438
444
  }
439
445
  }
440
446
  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.6",
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",