fix log output message and config parameter for log level
This commit is contained in:
parent
6942af8c29
commit
fe0b8ce102
@ -27,7 +27,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)
|
||||
@ -35,6 +36,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")
|
||||
|
||||
@ -181,6 +204,7 @@ def main():
|
||||
|
||||
logger = setup_logger()
|
||||
config = load_config(logger)
|
||||
set_log_level(config)
|
||||
|
||||
# get auth token
|
||||
logger.info("Try to get auth token")
|
||||
|
@ -5,3 +5,6 @@ PASSWORD = secret
|
||||
|
||||
[DNS]
|
||||
ZONE = example.com
|
||||
|
||||
[LOG]
|
||||
LEVEL = error
|
||||
|
Reference in New Issue
Block a user