Skip to main content

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


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-0.2.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

argparse_logging-0.2-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

Details for the file argparse_logging-0.2.tar.gz.

File metadata

  • Download URL: argparse_logging-0.2.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for argparse_logging-0.2.tar.gz
Algorithm Hash digest
SHA256 01069a43b3bf1735e206d8f50670392743c020fe3f0c7aa813c6a67615f2ff6f
MD5 f01eb01fe690a7585c74f1c6cc3605f4
BLAKE2b-256 2583a6f1451c51cd5e7dc1a313ccecb751eff95e12fe6963799940c7fb857697

See more details on using hashes here.

File details

Details for the file argparse_logging-0.2-py3-none-any.whl.

File metadata

  • Download URL: argparse_logging-0.2-py3-none-any.whl
  • Upload date:
  • Size: 2.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for argparse_logging-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 64655baa9d1a09c77a1230085a2026c1838612d3c9a31d369a38504fad4202be
MD5 662a8ea62bc2f7e85794259eab337030
BLAKE2b-256 36b6f4b1cc261e0b6c2f2438dddfee31f407674f378e2de49c46149d6e6fe573

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page