# utils/logger_utils.py
"""
Logging configuration and utilities
"""
import logging
import os
from config.settings import LOG_DIR

def setup_logger(name, log_file=None):
    logger = logging.getLogger(name)
    
    if not logger.handlers:
        logger.setLevel(logging.INFO)
        
        if log_file:
            os.makedirs(LOG_DIR, exist_ok=True)
            file_handler = logging.FileHandler(
                os.path.join(LOG_DIR, log_file)
            )
            file_handler.setFormatter(
                logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            )
            logger.addHandler(file_handler)
        
        console_handler = logging.StreamHandler()
        console_handler.setFormatter(
            logging.Formatter('%(levelname)s: %(message)s')
        )
        logger.addHandler(console_handler)
    
    return logger
