code: def test_redirected_logger():
      new_stdout = StringIO()
  
      with logger.set_level(logger.level_trace):
          # We do not test trace because CUML_LOG_TRACE is not compiled by
          # default
          test_msg = "This is a debug message"
          with redirect_stdout(new_stdout):
              logger.debug(test_msg)
          assert test_msg in new_stdout.getvalue()
  
          test_msg = "This is an info message"
          with redirect_stdout(new_stdout):
              logger.info(test_msg)
          assert test_msg in new_stdout.getvalue()
  
          test_msg = "This is a warn message"
          with redirect_stdout(new_stdout):
              logger.warn(test_msg)
          assert test_msg in new_stdout.getvalue()
  
          test_msg = "This is an error message"
          with redirect_stdout(new_stdout):
              logger.error(test_msg)
          assert test_msg in new_stdout.getvalue()
  
          test_msg = "This is a critical message"
          with redirect_stdout(new_stdout):
              logger.critical(test_msg)
          assert test_msg in new_stdout.getvalue()
  
      # Check that logging does not error with sys.stdout of None
      with redirect_stdout(None):
          test_msg = "This is a debug message"
          logger.debug(test_msg)
  
imports: from contextlib import redirect_stdout
  import cuml.internals.logger
  from io import StringIO, TextIOWrapper, BytesIO
label_desc: Use image node_id 2 for calling a global function with example usage: test_redirected_logger() without return types