diff --git a/default.toml b/default.toml index cf3a0bd..6fd8cc6 100644 --- a/default.toml +++ b/default.toml @@ -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" diff --git a/twoot.py b/twoot.py index 6abb955..2ff0366 100755 --- a/twoot.py +++ b/twoot.py @@ -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'])