From 163dcec1ae1b9ec8cd2fea69d4939bcdaa2164fe Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sat, 23 Jun 2018 19:40:24 +0200 Subject: [PATCH] transfer logging changes to cleanup script --- cleanup.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/cleanup.py b/cleanup.py index cfbf2f8..dabebd3 100755 --- a/cleanup.py +++ b/cleanup.py @@ -25,7 +25,8 @@ def setup_logger(): ch = logging.StreamHandler() ch.setLevel(logging.INFO) - formatter = logging.Formatter('%(asctime)s - %(name)s- %(levelname)s - %(message)s') + formatter = logging.Formatter( + '%(asctime)s - %(name)s - %(levelname)s: %(message)s', datefmt='%Y-%m-%d,%H:%M:%S') ch.setFormatter(formatter) # add handler to logger logger.addHandler(ch) @@ -33,6 +34,28 @@ def setup_logger(): return logger +def set_log_level(config): + try: + loglevel = str(config.get('LOG', 'LEVEL')).upper() + except (configparser.NoSectionError, configparser.NoOptionError) as e: + logger.error("Config error: %s" % (e)) + sys.exit(1) + + if loglevel == 'INFO': + level = logging.INFO + elif loglevel == 'ERROR': + level = logging.ERROR + elif loglevel == 'DEBUG': + level = logging.DEBUG + else: + level = logging.INFO + + logger = logging.getLogger('certbot_dns_corenetworks') + logger.setLevel(level) + for handler in logger.handlers: + handler.setLevel(level) + + def load_config(logger): config_path = os.path.join(os.path.expanduser("~"), ".certbot_dns_corenetworks", "config.ini") @@ -158,6 +181,7 @@ def main(): logger = setup_logger() config = load_config(logger) + set_log_level(config) # get auth token logger.info("Try to get auth token")