def hide_output(func: Callable[..., Any]) -> Callable[..., Any]:
    """Hide output of a function by redirecting stdout and stderr.

    This decorator captures and discards any output that would normally be printed
    to stdout or stderr when the decorated function executes. The function's
    return value is preserved.

    Args:
        func (Callable[..., Any]): Function whose output should be hidden.
            All output streams from this function will be captured.

    Returns:
        Callable[..., Any]: Wrapped function that executes silently.

    Raises:
        LoggerRedirectError: If an error occurs during function execution. The
            original exception can be accessed via ``__cause__``.

    Example:
        Basic usage to hide print statements:

        >>> @hide_output
        ... def my_function():
        ...     print("This will not be printed")
        >>> my_function()  # No output will appear

        Exceptions are still propagated:

        >>> @hide_output
        ... def my_function():
        ...     1/0  # doctest: +IGNORE_EXCEPTION_DETAIL
        >>> my_function()
        Traceback (most recent call last):
            ...
        LoggerRedirectError: Error occurred while executing my_function

    Note:
        - The decorator preserves the function's metadata using ``functools.wraps``
        - Both ``stdout`` and ``stderr`` streams are captured
        - Original streams are always restored, even if an exception occurs
    """

    @functools.wraps(func)
    def wrapper(*args: Any, **kwargs: Any) -> Any:  # noqa: ANN401
        """Wrapper function."""
        # redirect stdout and stderr to logger
        stdout = sys.stdout
        stderr = sys.stderr
        sys.stdout = io.StringIO()
        sys.stderr = io.StringIO()
        try:
            value = func(*args, **kwargs)
        except Exception as exception:
            msg = f"Error occurred while executing {func.__name__}"
            raise LoggerRedirectError(msg) from exception
        finally:
            sys.stdout = stdout
            sys.stderr = stderr
        return value

    return wrapper
Hide output of a function by redirecting stdout and stderr.

    This decorator captures and discards any output that would normally be printed
    to stdout or stderr when the decorated function executes. The function's
    return value is preserved.

    Args:
        func (Callable[..., Any]): Function whose output should be hidden.
            All output streams from this function will be captured.

    Returns:
        Callable[..., Any]: Wrapped function that executes silently.

    Raises:
        LoggerRedirectError: If an error occurs during function execution. The
            original exception can be accessed via ``__cause__``.

    Example:
        Basic usage to hide print statements:

        >>> @hide_output
        ... def my_function():
        ...     print("This will not be printed")
        >>> my_function()  # No output will appear

        Exceptions are still propagated:

        >>> @hide_output
        ... def my_function():
        ...     1/0  # doctest: +IGNORE_EXCEPTION_DETAIL
        >>> my_function()
        Traceback (most recent call last):
            ...
        LoggerRedirectError: Error occurred while executing my_function

    Note:
        - The decorator preserves the function's metadata using ``functools.wraps``
        - Both ``stdout`` and ``stderr`` streams are captured
        - Original streams are always restored, even if an exception occurs
    
src/anomalib/utils/logging.py