etler.load.logger — etler 0.1.0 documentation

# Source code for etler.load.logger

    import sys

    class LoggingStream:
        """
        Adapted from https://stackoverflow.com/questions/6796492/temporarily-redirect-stdout-stderr/6796752#6796752
        """

        def __init__(self, stdout=None, stderr=None):
            self._stdout = stdout or sys.stdout
            self._stderr = stderr or sys.stderr

        def __enter__(self):
            self.old_stdout, self.old_stderr = sys.stdout, sys.stderr
            self.old_stdout.flush()
            self.old_stderr.flush()
            sys.stdout, sys.stderr = self._stdout, self._stderr

        def __exit__(self, exc_type, exc_value, traceback):
            self._stdout.flush()
            self._stderr.flush()
            sys.stdout = self.old_stdout
            sys.stderr = self.old_stderr