This is a simple library to configure logging from command line argument when using argparse.
Project description
Argparse_logging
This is a simple library to configure logging from command line argument when using argparse.
Without argparse_logging
:
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument(
"--log-level",
default=logging.INFO,
type=lambda x: getattr(logging, x)),
help="Configure the logging level.",
)
args = parser.parse_args()
logging.basicConfig(level=args.log_level)
This is a bit annoying to copy paste in every program.
Instead you can use argparse_logging to get the following:
from argparse import ArgumentParser
from argparse_logging import add_log_level_argument
parser = ArgumentParser()
add_log_level_argument(parser)
args = parser.parse_args()
Deployment
You will need git
, pipenv
, python
, pre-commit
. Then you can set up your virtual environment:
$ git clone git@github.com:nanassito/argparse_logging.git
$ cd argparse_logging
$ pipenv update
Do whatever changes you want. You can run the tests and linting with:
$ pipenv run py.test
$ pre-commit
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
argparse_logging-1.0.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for argparse_logging-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a194650a589d087d7831acdf12b3c002a9c05bd932135d5a64137bcdcb9fdb1 |
|
MD5 | 296bdb62b5b17da42a1c7749e507d357 |
|
BLAKE2b-256 | 32b1f0fd32cab9977cc85523238c7bf24bc96608ba3e4233849041a0f26e83b5 |