Skip to main content

Like `subprocess.run`, but with the ability to pipe `stdout` and/or `stderr` to a `Logger` or capture each stream independently while the process is running.

Project description

run_with_logger

Like subprocess.run, but with the ability to pipe stdout and/or stderr to a Logger or capture each stream independently while the process is running.

Examples

Log stderr and capture stdout

The main process will wait for the subprocess while:

  • forwarding stderr line by line to the logger
  • capturing stdout in a CompletedProcess object, which is returned when the process finishes
from run_with_logger import run_with_logger
from logging import getLogger

logger = getLogger(__name__)

completed = run_with_logger(
    args=['foo', 'bar'],
    logger=logger,
    stdout_action="capture",
    stderr_action="log",
    check=False,
)

print(completed.stdout)

Log stdout and discard stderr

The main process will wait for the subprocess while:

  • forwarding stdout line by line to the logger
  • discarding stderr
from run_with_logger import run_with_logger
from logging import getLogger

logger = getLogger(__name__)

completed = run_with_logger(
    args=['foo', 'bar'],
    logger=logger,
    stdout_action="log",
    stderr_action="discard",
    check=False,
)

print(completed.stdout)

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

run_with_logger-1.0.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

run_with_logger-1.0.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file run_with_logger-1.0.1.tar.gz.

File metadata

  • Download URL: run_with_logger-1.0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for run_with_logger-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a65c7d30fac9bf77f461a79a33b39deb95138b0bf56217b729caa3475bb2a8f1
MD5 33fa7a257edb8bf0345a3928595f8a92
BLAKE2b-256 33dbd14f90dfcf6e9cb393a18bcc06ff9463e19b5b9e5283ca39851bde97e01f

See more details on using hashes here.

Provenance

The following attestation bundles were made for run_with_logger-1.0.1.tar.gz:

Publisher: publish.yml on rudolfbyker/run_with_logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file run_with_logger-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for run_with_logger-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 83d5c94b8ea55150b7ce9895206ed59602e0853754d21294f04acc1ed44cc00e
MD5 bac6da8fe2d5927f7f4b637fb69f5edc
BLAKE2b-256 5ddc5fdda415ce44b974a06e5d240be1b36033d12546a2476912dafec9e18177

See more details on using hashes here.

Provenance

The following attestation bundles were made for run_with_logger-1.0.1-py3-none-any.whl:

Publisher: publish.yml on rudolfbyker/run_with_logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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