code: def test_logger_error(self):
      # Check that we can reset the logger and error level
      HC = self.header_class
      hdr = HC()
      # Make a new logger
      str_io = StringIO()
      logger = logging.getLogger("test.logger")
      logger.addHandler(logging.StreamHandler(str_io))
      # Prepare a defect: bitpix not matching data type
      hdr["datatype"] = 16  # float32
      hdr["bitpix"] = 16  # severity 10
      logger.setLevel(10)
      log_cache = imageglobals.logger, imageglobals.error_level
      try:
          # Check log message appears in new logger
          imageglobals.logger = logger
          hdr.copy().check_fix()
          assert str_io.getvalue() == (
              "bitpix does not match datatype; setting bitpix to match datatype\n"
          )
          # Check that error_level in fact causes error to be raised
          imageglobals.error_level = 10
          with pytest.raises(HeaderDataError):
              hdr.copy().check_fix()
      finally:
          imageglobals.logger, imageglobals.error_level = log_cache
  
imports: import itertools
  import logging
  import os
  import pickle
  import re
  from io import BytesIO, StringIO
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ..None import imageglobals
  from ..analyze import AnalyzeHeader, AnalyzeImage
  from ..arraywriters import WriterError
  from ..casting import sctypes_aliases
  from ..nifti1 import Nifti1Header
  from ..optpkg import optional_package
  from ..spatialimages import HeaderDataError, HeaderTypeError, supported_np_types
  from ..testing import assert_dt_equal, bytesio_filemap, bytesio_round_trip, data_path, suppress_warnings
  from ..tmpdirs import InTemporaryDirectory
  from .None import test_spatialimages
  from .None import test_wrapstruct
label_desc: Use image node_id 12 for calling the TestAnalyzeHeader obj's underlying member method code with example usage: obj.test_logger_error() without return types