diff --git a/src/pricehist/cli.py b/src/pricehist/cli.py index 48bddee..274b073 100644 --- a/src/pricehist/cli.py +++ b/src/pricehist/cli.py @@ -8,19 +8,21 @@ from pricehist import __version__, outputs, sources from pricehist.fetch import fetch from pricehist.format import Format from pricehist.series import Series +from pricehist import logger def cli(args=None, output_file=sys.stdout): start_time = datetime.now() - logging.basicConfig(format="%(message)s", level=logging.INFO) + + logger.init() parser = build_parser() args = parser.parse_args() if args.debug: - logging.getLogger().setLevel(logging.DEBUG) + logger.show_debug() elif args.verbose: - logging.getLogger().setLevel(logging.INFO) + logger.show_info() logging.debug(f"Began pricehist run at {start_time}.") @@ -49,8 +51,8 @@ def cli(args=None, output_file=sys.stdout): ) if series.type not in source.types(): logging.critical( - f"ERROR: The requested price type '{series.type}' is not " - f"recognised by the {source.id()} source!" + f"The requested price type '{series.type}' is not " + f"recognized by the {source.id()} source!" ) sys.exit(1) fmt = Format.fromargs(args) diff --git a/src/pricehist/fetch.py b/src/pricehist/fetch.py index a48176c..312a836 100644 --- a/src/pricehist/fetch.py +++ b/src/pricehist/fetch.py @@ -46,19 +46,19 @@ def _cov_description( if start_uncovered == 0 and end_uncovered > 0: return ( - f"starting as requested and ending {end_uncovered} " - f"day{s(end_uncovered)} earlier than requested" + f"which ends {end_uncovered} day{s(end_uncovered)} earlier than " + f"requested" ) elif start_uncovered > 0 and end_uncovered == 0: return ( - f"starting {start_uncovered} day{s(start_uncovered)} later " - "than requested and ending as requested" + f"which starts {start_uncovered} day{s(start_uncovered)} later " + "than requested" ) elif start_uncovered > 0 and end_uncovered > 0: return ( - f"starting {start_uncovered} day{s(start_uncovered)} later " - f"and ending {end_uncovered} day{s(end_uncovered)} earlier " - "than requested" + f"which starts {start_uncovered} day{s(start_uncovered)} later " + f"and ends {end_uncovered} day{s(end_uncovered)} earlier " + f"than requested" ) else: return "as requested" diff --git a/src/pricehist/logger.py b/src/pricehist/logger.py new file mode 100644 index 0000000..c4ade60 --- /dev/null +++ b/src/pricehist/logger.py @@ -0,0 +1,26 @@ +import logging +import sys + + +class Formatter(logging.Formatter): + def format(self, record): + message = record.msg % record.args + if record.levelno == logging.INFO: + return message + else: + return f"{record.levelname} {message}" + + +def init(): + handler = logging.StreamHandler(sys.stderr) + handler.setFormatter(Formatter()) + logging.root.addHandler(handler) + logging.root.setLevel(logging.WARNING) + + +def show_debug(): + logging.root.setLevel(logging.DEBUG) + + +def show_info(): + logging.root.setLevel(logging.INFO)