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 --dev
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
Built Distribution
Close
Hashes for argparse_logging-2020.11.23.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 325b3b8d885e02f01df77b7dede13d5d7161961e8df9441213e509ae73f8a48e |
|
MD5 | f1d1e4d5a7abc2e878199edab6b418a7 |
|
BLAKE2b-256 | fdd3fd2cdadd8675ec92b2aa8f64642b3206e9761fc0889e885b0d07971a44da |
Close
Hashes for argparse_logging-2020.11.23-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0dda76b724fb589761ae139aa55bd3c451cde26c05bb797786c1a5ca1682425 |
|
MD5 | 90b8851f18d8df835f8787dd2b79af4b |
|
BLAKE2b-256 | c3e9eeb1172341d00d939f6fb9d1a67675fd6947757d806dc7d1a30c401b3eb1 |