18def setup_file_handler(path, log_name: str = "adctk.python.log"):
19 lp = os.getenv("ADC_LOG_DIRECTORY")
20 ll = os.getenv("ADC_LOG_LEVEL")
21 if path:
22 log_filepath = os.path.join(path, log_name)
23 else:
24 if lp:
25 log_filepath = os.path.join(lp, log_name)
26 else:
27 log_filepath = os.path.join(".", log_name)
28 lhandle = handlers.RotatingFileHandler(log_filepath, maxBytes = 10000000, backupCount = 10)
29 if ll:
30 lhandle.setLevel(ll)
31 else:
32 lhandle.setLevel(LOGLEVEL)
33 lhandle.setFormatter(LOGFORMATTER)
34 logger.addHandler(lhandle)
35 logger.debug("Setup file log handler at: %s", log_filepath)
36
37