subprocess-logger
Consolidated handler for subprocess logging in Python.
Overview
subprocess-logger provides a unified way to capture and forward output from Python subprocesses to the standard logging system. It is useful for applications that spawn subprocesses and want to collect their stdout and stderr streams in a thread-safe, structured manner.
Features
- Collects stdout and stderr from subprocesses and logs them using Python's
loggingmodule. - Allows log level customization at global and per process level for stdout and stderr.
- Thread-safe collection and dispatching of logs.
- Easy integration with existing logging configurations.
Installation
pip install subprocess-logger
Usage
Below is a basic usage example:
import logging
import subprocess
from subprocess_logger import install
# Configure root logger to print to console
logging.basicConfig(level=logging.DEBUG, format="%(levelname)s %(message)s")
# Create a collector instance
collector = install(stdout_level=logging.INFO, stderr_level=logging.WARNING)
# Start a subprocess that prints to stdout and stderr
proc = subprocess.Popen(
["python", "-c", "import sys; print('hello from stdout'); sys.stderr.write('hello from stderr\\n')"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Attach the subprocess to the collector
collector.attach(proc, logger_name="demo_subprocess")
# Wait for the subprocess to finish
proc.wait()
# Stop the collector (waits for all logs to be processed)
collector.stop()
Testing
To run unit tests, use the following command:
pytest
Or, if you have tox installed:
tox
License
This project is licensed under the MIT License.
Metadata
Release files for subprocess-logger 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| subprocess_logger-0.3.0.tar.gz | 5.3 kB | Without provenance | Details for subprocess_logger-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| subprocess_logger-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for subprocess_logger-0.3.0-py3-none-any.whl |
Total release size: 10.5 kB
Release files / subprocess_logger-0.3.0.tar.gz
| Download URL | subprocess_logger-0.3.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
348639f5429642f28cf5652f210e9f66719aa0c0d2d13ad2d688fd84a94ae734
|
|
BLAKE2b-256 checksum How to use checksums |
b557084e1afd45d16f9c5ae7de3cd52e8b79dacdb45f10155020df217c35db3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.6
|
Release files / subprocess_logger-0.3.0-py3-none-any.whl
| Download URL | subprocess_logger-0.3.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
03a1fdd2cd985fcfba810b915bcdf77f3b938eec4f6c12efbbb42335c21e312c
|
|
BLAKE2b-256 checksum How to use checksums |
49cd5995d7a71145ec8b342af1c6be0c06067d98f673f3c11cccde3adcd14b93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.6
|
Security for subprocess-logger 0.3.0
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.