code: def log_chk(hdr, level):
      """Utility method to check header checking / logging
  
      Asserts that log entry appears during ``hdr.check_fix`` for logging level
      below `level`.
  
      Parameters
      ----------
      hdr : instance
          Instance of header class, with methods ``copy`` and check_fix``.  The
          header has some minor error (defect) which can be detected with
          ``check_fix``.
      level : int
          Level (severity) of defect present in `hdr`.  When logging threshold is
          at or below `level`, a message appears in the default log (we test that
          happens).
  
      Returns
      -------
      hdrc : instance
          Header, with defect corrected.
      message : str
          Message generated in log when defect was detected.
      raiser : tuple
          Tuple of error type, callable, arguments that will raise an exception
          when then defect is detected.  Can be empty.  Check with ``if raiser !=
          (): assert_raises(*raiser)``.
      """
      str_io = StringIO()
      logger = logging.getLogger("test.logger")
      handler = logging.StreamHandler(str_io)
      logger.addHandler(handler)
      str_io.truncate(0)
      hdrc = hdr.copy()
      if level == 0:  # Should never log or raise error
          logger.setLevel(0)
          hdrc.check_fix(logger=logger, error_level=0)
          assert str_io.getvalue() == ""
          logger.removeHandler(handler)
          return hdrc, "", ()
      # Non zero defect level, test above and below threshold.
      # Set error level above defect level to prevent exception when defect
      # detected.
      e_lev = level + 1
      # Logging level above threshold, no log.
      logger.setLevel(level + 1)
      hdrc.check_fix(logger=logger, error_level=e_lev)
      assert str_io.getvalue() == ""
      # Logging level below threshold, log appears, store logged message
      logger.setLevel(level - 1)
      hdrc = hdr.copy()
      hdrc.check_fix(logger=logger, error_level=e_lev)
      assert str_io.getvalue() != ""
      message = str_io.getvalue().strip()
      logger.removeHandler(handler)
      # When error level == level, check_fix should raise an error
      hdrc2 = hdr.copy()
      raiser = (HeaderDataError, hdrc2.check_fix, logger, level)
      return hdrc, message, raiser
  
imports: import logging
  from io import BytesIO, StringIO
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from ..None import imageglobals
  from ..batteryrunners import Report
  from ..casting import sctypes
  from ..spatialimages import HeaderDataError
  from ..volumeutils import Recoder, native_code, swapped_code
  from ..wrapstruct import LabeledWrapStruct, WrapStruct, WrapStructError
label_desc: Use image node_id 1 for calling a global function with example usage: log_chk(hdr, level) and returns: hdrc,  message,  raiser, hdrc,  str,  