ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Functions | Variables
adctk.log Namespace Reference

Functions

 setup_file_handler (path, str log_name="adctk.python.log")
 
 setup_stream_handler (int level=logging.ERROR)
 

Variables

 LOGLEVEL = logging.DEBUG
 
str LOGFORMAT = "%(asctime)s [%(levelname)s] - %(message)s"
 
 LOGFORMATTER = logging.Formatter(LOGFORMAT)
 
 logger = logging.getLogger("adctk")
 

Function Documentation

◆ setup_file_handler()

adctk.log.setup_file_handler (   path,
str   log_name = "adctk.python.log" 
)
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

◆ setup_stream_handler()

adctk.log.setup_stream_handler ( int   level = logging.ERROR)
38def setup_stream_handler(level: int =logging.ERROR):
39 lhandle = logging.StreamHandler()
40 lhandle.setFormatter(LOGFORMATTER)
41 ll = os.getenv("ADC_LOG_LEVEL")
42 if ll:
43 numeric_level = getattr(logging, ll.upper(), None)
44 if not isinstance(numeric_level, int):
45 raise ValueError(f"Invalid log level: {ll}")
46 lhandle.setLevel(numeric_level)
47 else:
48 lhandle.setLevel(level)
49 logger.addHandler(lhandle)
50 logger.debug("Setup stream log handler")

Variable Documentation

◆ LOGFORMAT

str adctk.log.LOGFORMAT = "%(asctime)s [%(levelname)s] - %(message)s"

◆ LOGFORMATTER

adctk.log.LOGFORMATTER = logging.Formatter(LOGFORMAT)

◆ logger

adctk.log.logger = logging.getLogger("adctk")

◆ LOGLEVEL

adctk.log.LOGLEVEL = logging.DEBUG