Added log verbosity to config file

This commit is contained in:
jeancf 2022-12-04 11:45:45 +01:00
parent c9d4775085
commit b142664ef7
2 changed files with 23 additions and 5 deletions

View File

@ -67,3 +67,8 @@ subst_youtube = []
# e.g. subst_reddit = ["teddit.net", ]
# Default is []
subst_reddit = []
# Verbosity of log messages
# One of DEBUG, INFO, WARNING, ERROR, CRITICAL
# Default is "WARNING"
log_level = "WARNING"

View File

@ -38,10 +38,6 @@ from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalA
# Number of records to keep in db table for each twitter account
MAX_REC_COUNT = 50
# Set the desired verbosity of logging
# One of logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL
LOGGING_LEVEL = logging.INFO
# How many seconds to wait before giving up on a download (except video download)
HTTPS_REQ_TIMEOUT = 10
@ -94,6 +90,7 @@ def build_config(args):
'subst_twitter': [],
'subst_youtube': [],
'subst_reddit': [],
'log_level': "WARNING"
}
# Create default config object
@ -585,11 +582,27 @@ def main(argv):
# Setup logging to file
logging.basicConfig(
filename=TOML['config']['twitter_account'] + '.log',
level=LOGGING_LEVEL,
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
# Set level of logging
log_level = logging.WARNING
match TOML['options']['log_level'].upper():
case 'DEBUG':
log_level = logging.DEBUG
case 'INFO':
log_level = logging.INFO
case 'WARN':
log_level = logging.WARNING
case 'ERROR':
log_level = logging.ERROR
case 'CRITICAL':
log_level = logging.CRITICAL
case _:
logging.error('Invalid log_level %s in config file. Using WARN.', str(TOML['options']['log_level']))
logging.setLevel(log_level)
logging.info('Running with the following configuration:')
logging.info(' Config File : ' + str(args['f']))
logging.info(' twitter_account : ' + TOML['config']['twitter_account'])