A shared response utils package that provides api response functions and integrates request and response logging
npm install @pesalink/response-utils-packagePesaLink 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")
);
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