def add_file_handler(
    path: PurePath | str,
    *,
    filter: str | Callable[[str], bool] | None = None,
    level: int | str = logging.TRACE,  # type: ignore[attr-defined]
    id_: str = "",
) -> str:
    """Adds a file handler to all loggers that we have set up
    and all future loggers that will be set up with `get_logger`.

    Args:
        filter: If str: Check that the logger name contains the filter string.
            If callable: Check that the logger name satisfies the condition returned by the callable.
        level: The level of the handler.
        id_: The id of the handler. If not provided, a random id will be generated.

    Returns:
        The id of the handler. This can be used to remove the handler later.
    """
    Path(path).parent.mkdir(parents=True, exist_ok=True)
    handler = logging.FileHandler(path, encoding="utf-8")
    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
    handler.setFormatter(formatter)
    handler.setLevel(_interpret_level(level))
    with _LOG_LOCK:
        # Lock because other thread might be modifying the _SET_UP_LOGGERS set
        for name in _SET_UP_LOGGERS:
            if filter is not None:
                if isinstance(filter, str) and filter not in name:
                    continue
                if callable(filter) and not filter(name):
                    continue
            logger = logging.getLogger(name)
            logger.addHandler(handler)
    handler.my_filter = filter  # type: ignore
    if not id_:
        id_ = str(uuid.uuid4())
    _ADDITIONAL_HANDLERS[id_] = handler
    return id_
Adds a file handler to all loggers that we have set up
    and all future loggers that will be set up with `get_logger`.

    Args:
        filter: If str: Check that the logger name contains the filter string.
            If callable: Check that the logger name satisfies the condition returned by the callable.
        level: The level of the handler.
        id_: The id of the handler. If not provided, a random id will be generated.

    Returns:
        The id of the handler. This can be used to remove the handler later.
    
sweagent/utils/log.py