Skip to main content

pypi github

logging-actions

For easy configuration of logging.Loggers with argparse.Actions.

Use it like this:

>>> from logging_actions import log_level_action
>>> from argparse import ArgumentParser
>>> import logging

>>> logger = logging.getLogger("foo") # Create your script's logger
>>> logger.addHandler(logging.StreamHandler())  # Don't forget to add a handler!

>>> parser = ArgumentParser()
>>> _ = parser.add_argument("--log-level", action=log_level_action(logger)) # create an action for your module's logger
>>> args = parser.parse_args() # Your logger's level will be set for you when parsing

Features

Choices are handled transparently

foo.py --help

usage: foo.py [-h] [--log-level {critical,fatal,error,warn,warning,info,debug,notset}]

optional arguments:
  -h, --help            show this help message and exit
  --log-level {critical,fatal,error,warn,warning,info,debug,notset}
                        Set the logging level for foo.

If you specify a default the log-level will be set accordingly

parser.add_argument("-l", "--log-level", action=log_level_action(logger), default="info")

Custom levels are supported

logging.addLevelName(5, "TRACE")
parser.add_argument("-l", action=log_level_action(logger), default="trace")

Benefits

A better logging pattern

This replaces the following pattern for setting script log levels

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)

Manage multiple loggers easily

parser.add_argment("--foo-log-level", action=log_level_action(foo_logger))
parser.add_argment("--bar-log-level", action=log_level_action(bar_logger))

Metadata

Release files for logging-actions 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logging-actions 0.1.7
File Size Uploaded Provenance
logging-actions-0.1.7.tar.gz 3.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for logging-actions 0.1.7
File Interpreter ABI Platform
logging_actions-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 6.2 kB

Release files / logging-actions-0.1.7.tar.gz

Download URL logging-actions-0.1.7.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
aa6247b17baab17c51a3fbb926cc6b30220d180e038471f0df367c56b5a27a22
BLAKE2b-256 checksum
How to use checksums
ec98fea06a502033a285b24535e698bc05cf388f048de8bf3b0b7682cd577046
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.10 Linux/5.10.60.1-microsoft-standard-WSL2

Release files / logging_actions-0.1.7-py3-none-any.whl

Download URL logging_actions-0.1.7-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c17b871acba4a0279b98c1cf0d3d16f7d78d7e816308fff3e14933ec931b3ec0
BLAKE2b-256 checksum
How to use checksums
0c7d9ec492fda20df7ce6d3c6efbb6773d8ad2535e7cfbb563bc3fe7b4913104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.10 Linux/5.10.60.1-microsoft-standard-WSL2

Security for logging-actions 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page