import logging
import os

def setup_logging(log_file: str = None):
    log_format = "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
    logging.basicConfig(
        level=logging.INFO,
        format=log_format,
        datefmt="%Y-%m-%d %H:%M:%S",
    )
    if log_file:
        # Ensure the directory exists
        os.makedirs(os.path.dirname(log_file), exist_ok=True)
        file_handler = logging.FileHandler(log_file)
        file_handler.setFormatter(logging.Formatter(log_format, "%Y-%m-%d %H:%M:%S"))
        # Add the file handler to the root logger
        logging.getLogger().addHandler(file_handler)

def get_logger(name):
    return logging.getLogger(name)
