Module gplately.utils.log_utils
Expand source code
import logging.config
import logging.handlers
import os
import yaml
# configurate the logging utility
def setup_logging():
cfg_file_path = (
f"{os.path.dirname(os.path.realpath(__file__))}/../logging_config.yaml"
)
if os.path.isfile(cfg_file_path):
with open(cfg_file_path, "rt") as f:
config = yaml.safe_load(f.read())
logging.config.dictConfig(config)
for name in logging.root.manager.loggerDict:
logging.getLogger("gplately").debug(f"logger: {name}")
for h in logging.getLogger(name).handlers:
logging.getLogger("gplately").debug(h)
def turn_on_debug_logging():
debug_formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s [%(module)s:%(filename)s:%(lineno)s]"
)
gplately_logger = logging.getLogger("gplately")
gplately_logger.setLevel(logging.DEBUG)
for h in gplately_logger.handlers:
h.setLevel(logging.DEBUG)
h.setFormatter(debug_formatter)
ptt_logger = logging.getLogger("ptt")
ptt_logger.setLevel(logging.DEBUG)
for h in ptt_logger.handlers:
h.setLevel(logging.DEBUG)
h.setFormatter(debug_formatter)
gplately_logger.debug("The GPlately debug logging has been turned on.")
def get_debug_level():
if "GPLATELY_DEBUG" in os.environ:
if os.environ["GPLATELY_DEBUG"].lower() == "true":
return 1
try:
return int(os.environ["GPLATELY_DEBUG"])
except:
return 0
else:
return 0
Functions
def get_debug_level()
-
Expand source code
def get_debug_level(): if "GPLATELY_DEBUG" in os.environ: if os.environ["GPLATELY_DEBUG"].lower() == "true": return 1 try: return int(os.environ["GPLATELY_DEBUG"]) except: return 0 else: return 0
def setup_logging()
-
Expand source code
def setup_logging(): cfg_file_path = ( f"{os.path.dirname(os.path.realpath(__file__))}/../logging_config.yaml" ) if os.path.isfile(cfg_file_path): with open(cfg_file_path, "rt") as f: config = yaml.safe_load(f.read()) logging.config.dictConfig(config) for name in logging.root.manager.loggerDict: logging.getLogger("gplately").debug(f"logger: {name}") for h in logging.getLogger(name).handlers: logging.getLogger("gplately").debug(h)
def turn_on_debug_logging()
-
Expand source code
def turn_on_debug_logging(): debug_formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s [%(module)s:%(filename)s:%(lineno)s]" ) gplately_logger = logging.getLogger("gplately") gplately_logger.setLevel(logging.DEBUG) for h in gplately_logger.handlers: h.setLevel(logging.DEBUG) h.setFormatter(debug_formatter) ptt_logger = logging.getLogger("ptt") ptt_logger.setLevel(logging.DEBUG) for h in ptt_logger.handlers: h.setLevel(logging.DEBUG) h.setFormatter(debug_formatter) gplately_logger.debug("The GPlately debug logging has been turned on.")