nestjs-log-decorator 1.2.0 → 1.4.0

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/dist/index.cjs CHANGED
@@ -67,35 +67,39 @@ var LogWrapper = class {
67
67
  this.method = method;
68
68
  this.args = args;
69
69
  }
70
- invoked() {
70
+ invoked(message) {
71
71
  this.logger.log({
72
72
  method: this.method,
73
73
  state: "invoked",
74
- args: this.args
74
+ args: this.args,
75
+ ...message ? { message } : {}
75
76
  });
76
77
  }
77
- success() {
78
+ success(message) {
78
79
  this.logger.log({
79
80
  method: this.method,
80
81
  state: "success",
81
- args: this.args
82
+ args: this.args,
83
+ ...message ? { message } : {}
82
84
  });
83
85
  }
84
- error(error) {
86
+ error(error, message) {
85
87
  try {
86
88
  const pretifiedError = prettifyAxiosError(error);
87
89
  this.logger.error({
88
90
  method: this.method,
89
91
  state: "error",
90
92
  args: this.args,
91
- error: pretifiedError
93
+ error: pretifiedError,
94
+ ...message ? { message } : {}
92
95
  });
93
96
  } catch {
94
97
  this.logger.error({
95
98
  method: this.method,
96
99
  state: "error",
97
100
  args: this.args,
98
- error
101
+ error,
102
+ ...message ? { message } : {}
99
103
  });
100
104
  }
101
105
  }
@@ -441,7 +445,11 @@ exports.Log = Log;
441
445
  exports.LogWrapper = LogWrapper;
442
446
  exports.NO_LOG_METADATA_KEY = NO_LOG_METADATA_KEY;
443
447
  exports.NoLog = NoLog;
448
+ exports.applyToClass = applyToClass;
449
+ exports.applyToMethod = applyToMethod;
444
450
  exports.buildArgsObject = buildArgsObject;
445
451
  exports.createLogWrapper = createLogWrapper;
452
+ exports.getParameterNames = getParameterNames;
453
+ exports.handleAsyncExecution = handleAsyncExecution;
446
454
  exports.isLoggable = isLoggable;
447
455
  exports.prettifyAxiosError = prettifyAxiosError;
package/dist/index.d.cts CHANGED
@@ -45,9 +45,9 @@ declare class LogWrapper {
45
45
  private readonly method;
46
46
  private readonly args;
47
47
  constructor(logger: Logger, method: string, args: string | number | Record<string, unknown> | undefined);
48
- invoked(): void;
49
- success(): void;
50
- error(error: unknown): void;
48
+ invoked(message?: string): void;
49
+ success(message?: string): void;
50
+ error(error: unknown, message?: string): void;
51
51
  }
52
52
  /** If you see it, then you probably forgot to add `readonly logger = new Logger(YourClass.name)` to your class */
53
53
  interface Loggable {
@@ -292,4 +292,46 @@ declare const NoLog: () => (_target: unknown, _propertyKey: string, descriptor:
292
292
  //#region src/axios/axios.logger.d.ts
293
293
  declare function prettifyAxiosError(error: unknown): unknown;
294
294
  //#endregion
295
- export { Log, LogArgsFormatter, LogOptions, LogWrapper, Loggable, NO_LOG_METADATA_KEY, NoLog, buildArgsObject, createLogWrapper, isLoggable, prettifyAxiosError };
295
+ //#region src/decorate/applyToMethod.d.ts
296
+ type MethodFunction = (...args: unknown[]) => unknown;
297
+ /**
298
+ * Applies logging to a single method.
299
+ * @internal
300
+ */
301
+ declare const applyToMethod: (target: object, propertyKey: string, descriptor: PropertyDescriptor, {
302
+ onInvoke: shouldLogInvoke,
303
+ args: formatArgs
304
+ }?: LogOptions) => PropertyDescriptor;
305
+ /**
306
+ * Extracts parameter names from a function signature.
307
+ *
308
+ * This function parses the function's string representation to extract
309
+ * parameter names, handling TypeScript type annotations and default values.
310
+ *
311
+ * @param func - The function to extract parameter names from
312
+ * @returns Array of parameter names
313
+ *
314
+ * @example
315
+ * function example(id: number, name: string = 'default') {}
316
+ * getParameterNames(example) // Returns: ['id', 'name']
317
+ *
318
+ * @internal
319
+ */
320
+ declare const getParameterNames: (func: MethodFunction) => string[];
321
+ /**
322
+ * Handles execution of async methods with proper logging.
323
+ * @internal
324
+ */
325
+ declare const handleAsyncExecution: (result: Promise<unknown>, logWrapper: LogWrapper) => Promise<unknown>;
326
+ //#endregion
327
+ //#region src/decorate/applyToClass.d.ts
328
+ interface Constructor {
329
+ prototype: Record<string, unknown>;
330
+ }
331
+ /**
332
+ * Applies logging to all methods in a class.
333
+ * @internal
334
+ */
335
+ declare const applyToClass: (target: Constructor, options: LogOptions) => void;
336
+ //#endregion
337
+ export { Log, LogArgsFormatter, LogOptions, LogWrapper, Loggable, NO_LOG_METADATA_KEY, NoLog, applyToClass, applyToMethod, buildArgsObject, createLogWrapper, getParameterNames, handleAsyncExecution, isLoggable, prettifyAxiosError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-log-decorator",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Decorator that removes try catch boilerplate logging from NestJS service methods",
5
5
  "author": "Vlad Goncharov <leovs010@gmail.com>",
6
6
  "license": "AGPL-3.0",