aboutsummaryrefslogtreecommitdiff
path: root/src/wikiget
diff options
context:
space:
mode:
authorclpo13 <cody@lokken.dev>2023-10-23 09:52:40 -0700
committerGitHub <noreply@github.com>2023-10-23 09:52:40 -0700
commit775fb9e663d1704302cbc2329e9538c0c4353bf5 (patch)
tree1b11c79a7caf76a6934810a30f7c4d2a980c0303 /src/wikiget
parent9f210d54ccc86c21abf4ce4feef4593a60f3a72f (diff)
parente667b7f08aa6c7d9e4b7e8ed8003b17b9800fa56 (diff)
downloadwikiget-775fb9e663d1704302cbc2329e9538c0c4353bf5.tar.gz
wikiget-775fb9e663d1704302cbc2329e9538c0c4353bf5.zip
Merge pull request #10 from clpo13/refactor-args
Factor out usage of args object in log configuration
Diffstat (limited to 'src/wikiget')
-rw-r--r--src/wikiget/logging.py13
-rw-r--r--src/wikiget/wikiget.py2
2 files changed, 7 insertions, 8 deletions
diff --git a/src/wikiget/logging.py b/src/wikiget/logging.py
index 87b917c..290fd1d 100644
--- a/src/wikiget/logging.py
+++ b/src/wikiget/logging.py
@@ -16,7 +16,6 @@
# along with Wikiget. If not, see <https://www.gnu.org/licenses/>.
import logging
-from argparse import Namespace
import wikiget
@@ -26,14 +25,14 @@ class FileLogAdapter(logging.LoggerAdapter):
return f"[{self.extra['filename']}] {msg}", kwargs
-def configure_logging(args: Namespace) -> None:
+def configure_logging(verbosity: int, logfile: str, *, quiet: bool) -> None:
loglevel = logging.WARNING
- if args.verbose >= wikiget.VERY_VERBOSE:
+ if verbosity >= wikiget.VERY_VERBOSE:
# this includes API and library messages
loglevel = logging.DEBUG
- elif args.verbose >= wikiget.STD_VERBOSE:
+ elif verbosity >= wikiget.STD_VERBOSE:
loglevel = logging.INFO
- elif args.quiet:
+ elif quiet:
loglevel = logging.ERROR
# configure logging:
@@ -41,12 +40,12 @@ def configure_logging(args: Namespace) -> None:
# file log level is always debug (TODO: make this user configurable)
base_format = "%(message)s"
log_format = "[%(levelname)s] " + base_format
- if args.logfile:
+ if logfile:
# log to console and file
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s [%(levelname)-7s] " + base_format,
- filename=args.logfile,
+ filename=logfile,
)
console = logging.StreamHandler()
diff --git a/src/wikiget/wikiget.py b/src/wikiget/wikiget.py
index e64d00e..aee493f 100644
--- a/src/wikiget/wikiget.py
+++ b/src/wikiget/wikiget.py
@@ -119,7 +119,7 @@ def main() -> None:
# setup our environment
parser = construct_parser()
args = parser.parse_args()
- configure_logging(args)
+ configure_logging(verbosity=args.verbose, logfile=args.logfile, quiet=args.quiet)
# log events are appended to the file if it already exists, so note the start of a
# new download session