transfer logging changes to cleanup script

This commit is contained in:
Robert Kaussow 2018-06-23 19:40:24 +02:00
parent fe0b8ce102
commit 163dcec1ae

View File

@ -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")