code: def patch_std_streams(
      a_logger,
      connect_stdout=True,
      connect_stderr=True,
      load_config_defaults=True,
  ):
      if (
          (connect_stdout or connect_stderr)
          and not PrintPatchLogger.patched
          and (
              not running_remotely() or DEBUG_SIMULATE_REMOTE_TASK.get()
          )
      ):
          StdStreamPatch._stdout_proxy = (
              PrintPatchLogger(
                  sys.stdout,
                  a_logger,
                  level=logging.INFO,
                  load_config_defaults=load_config_defaults,
              )
              if connect_stdout and not sys.stdout.closed
              else None
          )
          StdStreamPatch._stderr_proxy = (
              PrintPatchLogger(
                  sys.stderr,
                  a_logger,
                  level=logging.ERROR,
                  load_config_defaults=load_config_defaults,
              )
              if connect_stderr and not sys.stderr.closed
              else None
          )
  
          if StdStreamPatch._stdout_proxy:
              # noinspection PyBroadException
              try:
                  if StdStreamPatch._stdout_original_write is None:
                      StdStreamPatch._stdout_original_write = (
                          sys.stdout.write
                      )
  
                  # this will only work in python 3, guard it with try/catch
                  if not hasattr(sys.stdout, "_original_write"):
                      sys.stdout._original_write = sys.stdout.write
                  sys.stdout.write = (
                      StdStreamPatch._stdout__patched__write__
                  )
              except Exception:
                  pass
              sys.stdout = StdStreamPatch._stdout_proxy
              # noinspection PyBroadException
              try:
                  sys.__stdout__ = sys.stdout
              except Exception:
                  pass
  
          if StdStreamPatch._stderr_proxy:
              # noinspection PyBroadException
              try:
                  if StdStreamPatch._stderr_original_write is None:
                      StdStreamPatch._stderr_original_write = (
                          sys.stderr.write
                      )
                  if not hasattr(sys.stderr, "_original_write"):
                      sys.stderr._original_write = sys.stderr.write
                  sys.stderr.write = (
                      StdStreamPatch._stderr__patched__write__
                  )
              except Exception:
                  pass
              sys.stderr = StdStreamPatch._stderr_proxy
  
              # patch the base streams of sys (this way colorama will keep its ANSI colors)
              # noinspection PyBroadException
              try:
                  sys.__stderr__ = sys.stderr
              except Exception:
                  pass
  
          # now check if we have loguru and make it re-register the handlers
          # because it stores internally the stream.write function, which we cant patch
          # noinspection PyBroadException
          try:
              from loguru import logger  # noqa
  
              register_stderr = None
              register_stdout = None
              for k, v in logger._handlers.items():  # noqa
                  if connect_stderr and v._name == "<stderr>":  # noqa
                      register_stderr = k
                  elif connect_stdout and v._name == "<stdout>":  # noqa
                      register_stderr = k
              if register_stderr is not None:
                  logger.remove(register_stderr)
                  logger.add(sys.stderr)
              if register_stdout is not None:
                  logger.remove(register_stdout)
                  logger.add(sys.stdout)
          except Exception:
              pass
  
      elif (
          connect_stdout or connect_stderr
      ) and not running_remotely():
          if StdStreamPatch._stdout_proxy and connect_stdout:
              StdStreamPatch._stdout_proxy.connect(a_logger)
          if StdStreamPatch._stderr_proxy and connect_stderr:
              StdStreamPatch._stderr_proxy.connect(a_logger)
  
imports: import logging
  import sys
  from time import time
  from ..binding.frameworks import _patched_call
  from ..config import running_remotely, config, DEBUG_SIMULATE_REMOTE_TASK
  from ..utilities.process.mp import ForkSafeRLock
label_desc: Use image node_id 1 for calling the StdStreamPatch obj's underlying member method code with example usage: obj.patch_std_streams(a_logger, connect_stdout, connect_stderr, load_config_defaults) without return types