class_docstr: Context manager to redirect stdout and stderr to logger.
class_docstr_tok: ["Context","manager","to","redirect","stdout","and","stderr","to","logger","."]
code: def __init__(self, logger: Optional[logging.Logger] = None):
      self.logger = logger or DummyLogger("dummy")
      # Current Python process redirects
      self.redirect_stdout = redirect_stdout(
          LoggerWriter(self.logger.info)
      )
      self.redirect_stderr = redirect_stderr(
          LoggerWriter(self.logger.warning)
      )
      # This redirects stdout/stderr from C libraries and child processes (joblib)
      self.c_redirect = (
          pipes(
              stdout=LoggerWriter(self.logger.info),
              stderr=LoggerWriter(self.logger.warning),
          )
          if pipes
          else None
      )
  
imports: import logging
  import os
  import traceback
  import warnings
  from contextlib import redirect_stderr, redirect_stdout
  from typing import Callable, Optional, Union
label_desc: Use image node_id 1 to create a new redirect_output object  with example: obj = redirect_output(logger)