diff options
| author | Cody Logan <cody@lokken.dev> | 2023-10-20 16:31:56 -0700 |
|---|---|---|
| committer | Cody Logan <cody@lokken.dev> | 2023-10-20 16:33:37 -0700 |
| commit | 3d37cf6f86eb6c48a3a0a094c42ade6d7aed1daf (patch) | |
| tree | 699fc34834fb345a63cecaf29643c315a3312db8 /src/wikiget/wikiget.py | |
| parent | b136af078208882ae696b21c0d8aac009e7468d4 (diff) | |
| download | wikiget-3d37cf6f86eb6c48a3a0a094c42ade6d7aed1daf.tar.gz wikiget-3d37cf6f86eb6c48a3a0a094c42ade6d7aed1daf.zip | |
Move logging configuration to new file
Also, use a LoggerAdapter to add contextual info (such as filenames)
to log messages when downloading, especially useful with threaded
batch processing.
Diffstat (limited to 'src/wikiget/wikiget.py')
| -rw-r--r-- | src/wikiget/wikiget.py | 31 |
1 files changed, 1 insertions, 30 deletions
diff --git a/src/wikiget/wikiget.py b/src/wikiget/wikiget.py index e9a1147..5b84dac 100644 --- a/src/wikiget/wikiget.py +++ b/src/wikiget/wikiget.py @@ -25,6 +25,7 @@ from requests import ConnectionError, HTTPError import wikiget from wikiget.dl import batch_download, download, prep_download from wikiget.exceptions import ParseError +from wikiget.logging import configure_logging def construct_parser(): @@ -114,36 +115,6 @@ def construct_parser(): return parser -def configure_logging(args): - loglevel = logging.WARNING - if args.verbose >= wikiget.VERY_VERBOSE: - # this includes API and library messages - loglevel = logging.DEBUG - elif args.verbose >= wikiget.STD_VERBOSE: - loglevel = logging.INFO - elif args.quiet: - loglevel = logging.ERROR - - # configure logging: - # console log level is set via -v, -vv, and -q options; - # file log level is always debug (TODO: make this user configurable) - base_format = "%(threadName)s - %(message)s" - log_format = "[%(levelname)s] " + base_format - if args.logfile: - # log to console and file - logging.basicConfig( - level=logging.DEBUG, - format="%(asctime)s [%(levelname)-7s] " + base_format, - filename=args.logfile, - ) - - console = logging.StreamHandler() - console.setLevel(loglevel) - console.setFormatter(logging.Formatter(log_format)) - logging.getLogger("").addHandler(console) - else: - # log only to console - logging.basicConfig(level=loglevel, format=log_format) def main(): # setup our environment parser = construct_parser() |
