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 aCompletedProcess
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
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
run_with_logger-1.0.0.tar.gz
(8.5 kB
view details)
Built Distribution
File details
Details for the file run_with_logger-1.0.0.tar.gz
.
File metadata
- Download URL: run_with_logger-1.0.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76e140d94c627831e2f7833fd4e142781b74dc31bc6990c526477a47f1171d1b |
|
MD5 | 9d9fd64a0629ac115f4d622d26418055 |
|
BLAKE2b-256 | 2f99acd713939ebc2ab631570cf2396507755408fa0445649a46812b8cf8f708 |
File details
Details for the file run_with_logger-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: run_with_logger-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 729b9cc61cc910a8174682a06abd22753f264c24e544192d3a92c405dd34acdd |
|
MD5 | f61e2b79823e313ab617e928e720e1fe |
|
BLAKE2b-256 | 2c94dba4099a4fc111e86299b60877ff2b6066ce50532c3fa9273f0cdfd3cd55 |