code: def test_logging_to_a_file(dst=None):
      ok_(not exists(dst))
  
      lgr = LoggerHelper("dataladtest-1").get_initialized_logger(
          logtarget=dst
      )
      ok_(exists(dst))  # nothing was logged -- no file created
  
      msg = "Oh my god, they killed Kenny"
      lgr.error(msg)
      with open(dst) as f:
          lines = f.readlines()
      assert_equal(
          len(lines), 1, "Read more than a single log line: %s" % lines
      )
      line = lines[0]
      ok_(msg in line)
      ok_(
          "\033[" not in line,
          msg="There should be no color formatting in log files. Got: %s"
          % line,
      )
      # verify that time stamp and level are present in the log line
      # do not want to rely on not having race conditions around date/time changes
      # so matching just with regexp
      # (...)? is added to swallow possible traceback logs
      regex = r"\[ERROR\]"
      if EnsureBool()(dl_cfg.get("datalad.log.timestamp", False)):
          regex = r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} " + regex
      if EnsureBool()(dl_cfg.get("datalad.log.vmem", False)):
          regex += r" RSS/VMS: \S+/\S+( \S+)?\s*"
      regex += r"(\s+\S+\s*)? " + msg
      assert_re_in(regex, line, match=True)
  
      # Python's logger is ok (although not documented as supported) to accept
      # non-string messages, which could be str()'ed.  We should not puke
      msg2 = "Kenny is alive"
      lgr.error(RuntimeError(msg2))
      with open(dst) as f:
          assert_in(msg2, f.read())
  
      # Close all handlers so windows is happy -- apparently not closed fast enough
      for handler in lgr.handlers:
          handler.close()
      assert_no_open_files(dst)
  
imports: import inspect
  import logging
  import os.path
  from logging import makeLogRecord
  from os.path import exists
  from unittest.mock import patch
  from datalad import cfg
  from datalad.log import ColorFormatter, LoggerHelper, TraceBack, log_progress, with_progress, with_result_progress
  from datalad.support import ansi_colors
  from datalad.support.constraints import EnsureBool
  from datalad.tests.utils_pytest import SkipTest, assert_equal, assert_in, assert_no_open_files, assert_not_in, assert_re_in, known_failure_githubci_win, ok_, ok_endswith, ok_generator, swallow_logs, with_tempfile
  from datalad.utils import on_windows
label_desc: Use image node_id 1 for calling a global function with example usage: test_logging_to_a_file(dst) without return types