Add logging.
This commit is contained in:
parent
66ff045f42
commit
a703b83b00
1 changed files with 25 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from textwrap import TextWrapper
|
from textwrap import TextWrapper
|
||||||
|
@ -8,9 +9,19 @@ from pricehist.format import Format
|
||||||
|
|
||||||
|
|
||||||
def cli(args=None):
|
def cli(args=None):
|
||||||
|
start_time = datetime.now()
|
||||||
|
logging.basicConfig(format="%(message)s", level=logging.INFO)
|
||||||
|
|
||||||
parser = build_parser()
|
parser = build_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.verbose:
|
||||||
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
|
elif args.debug:
|
||||||
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
logging.debug(f"pricehist started at {start_time}")
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
cmd_version()
|
cmd_version()
|
||||||
elif args.command == "sources":
|
elif args.command == "sources":
|
||||||
|
@ -22,6 +33,8 @@ def cli(args=None):
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
|
logging.debug(f"pricehist finished at {datetime.now()}")
|
||||||
|
|
||||||
|
|
||||||
def cmd_version():
|
def cmd_version():
|
||||||
print(f"pricehist v{__version__}")
|
print(f"pricehist v{__version__}")
|
||||||
|
@ -145,12 +158,23 @@ def build_parser():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v",
|
|
||||||
"--version",
|
"--version",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="show version information",
|
help="show version information",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logging_group = parser.add_mutually_exclusive_group(required=False)
|
||||||
|
logging_group.add_argument(
|
||||||
|
"--verbose",
|
||||||
|
action="store_true",
|
||||||
|
help="show INFO messages",
|
||||||
|
)
|
||||||
|
logging_group.add_argument(
|
||||||
|
"--debug",
|
||||||
|
action="store_true",
|
||||||
|
help="show INFO and DEBUG messages",
|
||||||
|
)
|
||||||
|
|
||||||
subparsers = parser.add_subparsers(title="commands", dest="command")
|
subparsers = parser.add_subparsers(title="commands", dest="command")
|
||||||
|
|
||||||
subparsers.add_parser(
|
subparsers.add_parser(
|
||||||
|
|
Loading…
Add table
Reference in a new issue