1.1.14 • Published 9 months ago

@pesalink/response-utils-package v1.1.14

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

PesaLink Logger The PesaLink Logger package provides utilities to enhance logging capabilities for your Node.js applications. It allows you to log method calls dynamically for class prototypes and supports advanced logging strategies such as AOP (Aspect-Oriented Programming). This package includes two main components: AOPLogger and AOPLoggerUtils.

Features Dynamic Logging: Log all method calls on a class prototype. Exclusion Support: Exclude specific methods from being logged. Error-Only Logging: Configure methods to log only errors. Custom Advice Types: Choose the logging strategy (around, before, after). Utility-Driven Approach: Use either AOPLogger directly or the AOPLoggerUtils method logMethodsWithAOP. Installation Install the package using npm:

bash Copy code npm install pesalink-logger Usage 1. Using AOPLogger Directly AOPLogger is the core utility to log individual method calls on a class prototype. You can call it directly to configure logging for specific methods.

javascript Copy code const AOPLogger = require("pesalink-logger/aopLogger");

AOPLogger.logMethodCall( classPrototype, // The class prototype methodName, // Name of the method to log className, // Name of the class methodType, // Optional: Type of method (e.g., "getAll" for error logging) adviceType, // Optional: Type of advice (default: "around") classType // Optional: Class type for custom logging ); 2. Using AOPLoggerUtils.logMethodsWithAOP The logMethodsWithAOP method in AOPLoggerUtils simplifies logging for all methods in a class prototype, with options to exclude specific methods or log errors only for some.

javascript Copy code const { logMethodsWithAOP } = require("pesalink-logger/aopLoggerUtils");

logMethodsWithAOP( classPrototype, // Prototype of the class excludedMethods = [], // Methods to exclude from logging logErrorsOnly = [], // Methods to log only errors (e.g., "getAll") className, // Name of the class for logging context classType, // Optional: Class type for custom strategies adviceType = "around" // Optional: Advice type (default: "around") );

Parameters for logMethodsWithAOP

Parameter Description classPrototype The prototype of the class whose methods you want to log. excludedMethods Array of method names to exclude from logging. logErrorsOnly Array of methods for which only errors should be logged (e.g., getAll). className The name of the class (used for logging context). classType The type of the class (optional, used in custom logging strategies). adviceType The type of advice (optional, default is "around" for method execution). Example: Dynamic Logging Below is an example demonstrating the use of AOPLoggerUtils to log method calls dynamically on a class:

const { logMethodsWithAOP } = require("pesalink-logger/aopLoggerUtils");

class MyService {
  constructor() {}

  fetchData() {
    console.log("Fetching data...");
  }

  saveData() {
    console.log("Saving data...");
  }

  getAll() {
    throw new Error("An error occurred while fetching all data!");
  }
}

// Exclude `saveData` and log only errors for `getAll`
logMethodsWithAOP(
  MyService.prototype,
  ["saveData"],        // Excluded methods
  ["getAll"],          // Log errors only
  "MyService"          // Class name
);

// Instantiate and test logging
const service = new MyService();
service.fetchData();
try {
  service.getAll();
} catch (error) {}

Integration Notes The AOPLogger class provides the low-level API for method call logging. The AOPLoggerUtils.logMethodsWithAOP method wraps around AOPLogger to simplify configuration for dynamic logging of class prototypes. Both utilities are included in the pesalink-logger package and can be used interchangeably based on your project needs.

1.1.14

9 months ago

1.1.13

9 months ago

1.1.12

9 months ago

1.1.11

9 months ago

1.1.10

9 months ago

1.1.0

9 months ago

1.0.99

9 months ago

1.0.98

9 months ago

1.0.97

10 months ago

1.0.96

10 months ago

1.0.95

10 months ago

1.0.94

10 months ago

1.0.93

10 months ago

1.0.92

10 months ago

1.0.91

10 months ago

1.0.90

10 months ago

1.0.89

10 months ago

1.0.88

10 months ago

1.0.87

10 months ago

1.0.86

10 months ago

1.0.8

10 months ago

1.0.85

10 months ago

1.0.84

10 months ago

1.0.83

10 months ago

1.0.82

10 months ago

1.0.81

10 months ago

1.0.80

10 months ago

1.0.79

11 months ago

1.0.78

11 months ago

1.0.77

11 months ago

1.0.76

11 months ago

1.0.75

11 months ago

1.0.74

11 months ago

1.0.73

11 months ago

1.0.72

11 months ago

1.0.71

11 months ago

1.0.70

11 months ago

1.0.69

11 months ago

1.0.68

11 months ago

1.0.67

11 months ago

1.0.66

11 months ago

1.0.65

11 months ago

1.0.64

11 months ago

1.0.63

11 months ago

1.0.62

11 months ago

1.0.61

11 months ago

1.0.60

1 year ago