Exception and Logging Code
Exception and Logging Code
"""
Custom exception class for handling specific exceptions in the project.
"""
@staticmethod
def get_detailed_error_message(error_message: str, error_detail: sys) -> str:
"""
Generate a detailed error message including the error type, file name, line
number, and error message.
def __str__(self):
"""
Return the string representation of the CustomException.
def __repr__(self):
"""
Return the string representation of the CustomException for debugging
purposes.
import logging
import os
from datetime import datetime
LOG_FILE = f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log"
logs_path = os.path.join(os.getcwd(), "logs", LOG_FILE)
os.makedirs(logs_path, exist_ok=True)
logging.basicConfig(
filename=LOG_FILE_PATH,
format="[%(asctime)s] %(lineno)d %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
)
Certainly! Let's break down the code and explain each part in detail.
The code you provided consists of two main parts: a custom exception class called
CustomException and a logging configuration.
CustomException class: