tfparse icon indicating copy to clipboard operation
tfparse copied to clipboard

configure logging

Open mirettig opened this issue 5 months ago • 1 comments

I would love a way to tell the logging to not report being unable to parse import blocks. While using tfparse, I run it in directories with many import blocks and it generates a lot of useless logging. I can ignore and delete the blocks once they are no longer needed, but it will still happen every once in a while.

mirettig avatar Aug 07 '25 13:08 mirettig

I worked my way around this with a context manager:

@contextmanager
def suppress_stdout_stderr():
    """
    Context manager to suppress stdout and stderr at the OS file descriptor level
    """
    devnull = os.open(os.devnull, os.O_WRONLY)
    old_stdout_fd = os.dup(1)
    old_stderr_fd = os.dup(2)
    try:
        os.dup2(devnull, 1)
        os.dup2(devnull, 2)
        yield
    finally:
        os.dup2(old_stdout_fd, 1)
        os.dup2(old_stderr_fd, 2)
        os.close(devnull)
        os.close(old_stdout_fd)
        os.close(old_stderr_fd)

You can then use it like so:

with suppress_stdout_stderr():
    data = load_from_path(self.path)

johannespostler avatar Sep 18 '25 14:09 johannespostler