UNPKG

kist

Version:

Package Pipeline Processor

97 lines (96 loc) 3.65 kB
"use strict"; // ============================================================================ // Import // ============================================================================ Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractProcess = void 0; const Logger_1 = require("../../logger/Logger"); // ============================================================================ // Class // ============================================================================ /** * AbstractProcess provides consistent logging functionality to its subclasses. * It leverages a centralized logger to manage different log levels and * ensures logging consistency across the application. */ class AbstractProcess { // Constructor // ======================================================================== /** * Constructs an AbstractProcess instance. * Initializes the logger to ensure logging capabilities are available to * subclasses. */ constructor() { this.logger = Logger_1.Logger.getInstance(); } // Logging Methods // ======================================================================== /** * Logs an informational message with the originating class name as context. * Use this for standard informational messages. * @param message - The message to log. */ logInfo(message) { this.logger.logInfo(this.constructor.name, message); } /** * Logs a debug message with the originating class name as context. * @param message - The debug message to log. */ logDebug(message) { this.logger.logDebug(this.constructor.name, message); } /** * Logs a warning message with the originating class name as context. * Use this to highlight potential issues that are non-critical. * @param message - The warning message to log. */ logWarn(message) { this.logger.logWarn(this.constructor.name, message); } /** * Logs an error message with the originating class name as context. * Handles any type of error and ensures consistent error reporting. * Use this for logging critical issues or exceptions. * * @param message - A custom message providing additional context for * the error. * @param error - (Optional) The error to log. Can be a string, an Error * object, or other types. */ logError(message, error) { const errorMessage = this.formatError(message, error); this.logger.logError(this.constructor.name, errorMessage); } /** * Formats an error message for logging. * Combines a custom message with additional error details if available. * * @param message - The base error message. * @param error - Additional error information, such as an Error object. * @returns A formatted string combining the message and error details. */ formatError(message, error) { if (error instanceof Error) { return `${message}: ${error.message}`; } else if (typeof error === "string") { return `${message}: ${error}`; } else if (error) { return `${message}: ${JSON.stringify(error)}`; } return message; } /** * Logs a success message with the originating class name as context. * Use this to indicate successful completion of a process or step. * * @param message - The success message to log. */ logSuccess(message) { this.logger.logInfo(this.constructor.name, message); } } exports.AbstractProcess = AbstractProcess;