def test_configfile(self): previous_dir = os.getcwd() with TemporaryDirectory() as tempdir: os.chdir(tempdir) with open('ocrd_logging.py', 'w') as f: f.write('print("this is mighty dangerous")') initLogging() os.chdir(previous_dir)
def test_loglevel_override(self): import logging self.assertEqual( logging.getLogger('').getEffectiveLevel(), logging.INFO) self.assertEqual( logging.getLogger('PIL').getEffectiveLevel(), logging.INFO) result = self.runner.invoke(cli_with_ocrd_loglevel, ['--log-level', 'DEBUG']) self.assertEqual(result.exit_code, 0) self.assertEqual( logging.getLogger('PIL').getEffectiveLevel(), logging.DEBUG) initLogging()
def test_configured_dateformat(logging_conf, capsys): """Ensure example ocrd_logging.conf is valid and produces desired record format""" # arrange os.chdir(logging_conf) initLogging() test_logger = getLogger('') # act test_logger.info("test logger initialized") log_info_output = capsys.readouterr().out must_not_match = r"^\d{4}-\d{2}-\d{2}.*" assert not re.match(must_not_match, log_info_output) match_pattern = r"^\d{2}:\d{2}:\d{2}.*" assert re.match(match_pattern, log_info_output)
def test_configured_shapely_logger_present(logging_conf, capsys): """Ensure example ocrd_logging.conf is valid and contains logger shapely.geos""" # arrange os.chdir(logging_conf) initLogging() logger_under_test = getLogger('shapely.geos') # act info logger_under_test.info("shapely.geos logger initialized") log_info_output = capsys.readouterr().out assert not log_info_output # act error logger_under_test.error("shapely alert") log_error_output = capsys.readouterr().out assert log_error_output
def test_configured_tensorflow_logger_present(logging_conf, capsys): """Ensure example ocrd_logging.conf is valid and contains logger tensorflow""" # arrange os.chdir(logging_conf) initLogging() logger_under_test = getLogger('tensorflow') # act info logger_under_test.info("tensorflow logger initialized") log_info_output = capsys.readouterr().out assert not log_info_output # act error logger_under_test.error("tensorflow has error") log_error_output = capsys.readouterr().out assert log_error_output
def setUp(self): initLogging() self.runner = CliRunner()
def resetLogging(): disableLogging() initLogging()
def setUp(self): initLogging()
""" def __init__(self, level="INFO"): self.level = level self.linebuf = '' def write(self, buf): for line in buf.rstrip().splitlines(): loguru.logger.log(self.level, line.rstrip()) def flush(self): pass # Initialize ocrd logging because we want to have this before # we start logging our stuff. initLogging() # Configure logging to grep logging from other modules. logging.basicConfig(handlers=[InterceptHandler()], level=0) logging.getLogger().handlers = [InterceptHandler()] logging.getLogger(None).setLevel("DEBUG") # Initialize our logging via loguru. loguru.logger.add(f"{config.LOGGER_PATH}/ocrd-butler.log", rotation="06:00", retention="20 days", compression="gz") # If we start as service allow logging for other users. try: os.chmod(f"{config.LOGGER_PATH}/ocrd-butler.log", 0o766) except PermissionError: