test24 / api /logger.py
Niansuh's picture
Upload 15 files
00a7e34 verified
import logging
# Setup logger with a consistent format
def setup_logger(name):
logger = logging.getLogger(name)
if not logger.handlers:
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# Console handler
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
# File Handler - Error Level
# error_file_handler = logging.FileHandler('error.log')
# error_file_handler.setFormatter(formatter)
# error_file_handler.setLevel(logging.ERROR)
# logger.addHandler(error_file_handler)
return logger
logger = setup_logger(__name__)
# Log functions to structure specific logs in utils.py
def log_generated_chat_id_with_referer(chat_id, model, referer_url):
"""
Log the generated Chat ID with model and referer URL if it exists.
"""
logger.info(f"Generated Chat ID: {chat_id} - Model: {model} - URL: {referer_url}")
def log_model_delay(delay_seconds, model, chat_id):
"""
Log the delay introduced for specific models.
"""
logger.info(f"Introducing a delay of {delay_seconds} seconds for model '{model}' (Chat ID: {chat_id})")
def log_http_error(error, chat_id):
"""
Log HTTP errors encountered during requests.
"""
logger.error(f"HTTP error occurred for Chat ID {chat_id}: {error}")
def log_request_error(error, chat_id):
"""
Log request errors unrelated to HTTP status.
"""
logger.error(f"Request error occurred for Chat ID {chat_id}: {error}")
def log_strip_prefix(model_prefix, content):
"""
Log when a model prefix is stripped from the content.
"""
logger.debug(f"Stripping prefix '{model_prefix}' from content.")