import logging
import os

def setup_logger(level=None):
    if level is None:
        if os.getenv("LLM_SEARCH_DEBUG", "0").strip().lower() in ("1", "true"):
            level = logging.DEBUG
        else:
            level = logging.INFO

    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        "%(asctime)s|%(filename)s:%(lineno)d|%(levelname)s|> %(message)s"
    )
    handler.setFormatter(formatter)

    _logger = logging.getLogger("llm_search_logger")
    _logger.setLevel(level)
    _logger.addHandler(handler)
    _logger.propagate = False
    return _logger

logger = setup_logger()
