diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-24 17:18:07 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-24 17:18:07 +0200 |
commit | 19d3c02396ac1c00742e50e60a0a840fbfade1ac (patch) | |
tree | 31ada80cf14a889b34ba5bdc075ab76e0a2cf17d /crates/yt_dlp | |
parent | chore(treewide): Add missing license headers (diff) | |
download | yt-19d3c02396ac1c00742e50e60a0a840fbfade1ac.zip |
style(treewide): Format
Diffstat (limited to 'crates/yt_dlp')
-rw-r--r-- | crates/yt_dlp/crates/pyo3-pylogger/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/yt_dlp/crates/pyo3-pylogger/README.md | 32 | ||||
-rw-r--r-- | crates/yt_dlp/src/options.rs | 4 |
3 files changed, 32 insertions, 10 deletions
diff --git a/crates/yt_dlp/crates/pyo3-pylogger/Cargo.toml b/crates/yt_dlp/crates/pyo3-pylogger/Cargo.toml index 259ea98..6375528 100644 --- a/crates/yt_dlp/crates/pyo3-pylogger/Cargo.toml +++ b/crates/yt_dlp/crates/pyo3-pylogger/Cargo.toml @@ -12,7 +12,11 @@ name = "pyo3-pylogger" version = "0.5.0" edition = "2021" -authors = ["Dylan Bobby Storey <dylan.storey@gmail.com>", "cpu <daniel@binaryparadox.net>" , "Warren Snipes <contact@warrensnipes.dev>"] +authors = [ + "Dylan Bobby Storey <dylan.storey@gmail.com>", + "cpu <daniel@binaryparadox.net>", + "Warren Snipes <contact@warrensnipes.dev>", +] description = "Enables `log` for pyo3 based Rust applications using the `logging` modules." publish = ["crates-io"] license = "Apache-2.0" diff --git a/crates/yt_dlp/crates/pyo3-pylogger/README.md b/crates/yt_dlp/crates/pyo3-pylogger/README.md index 1f6c419..e68903b 100644 --- a/crates/yt_dlp/crates/pyo3-pylogger/README.md +++ b/crates/yt_dlp/crates/pyo3-pylogger/README.md @@ -12,14 +12,19 @@ If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. # pyo3-pylogger -Enables log messages for pyo3 embedded Python applications using Python's `logging` or module. +Enables log messages for pyo3 embedded Python applications using Python's +`logging` or module. # Features + - Logging integration between Python's `logging` module and Rust's `log` crate -- Structured logging support via the logging [extra](https://docs.python.org/3/library/logging.html#logging.Logger.debug) field (requires `kv` or `tracing-kv`feature) +- Structured logging support via the logging + [extra](https://docs.python.org/3/library/logging.html#logging.Logger.debug) + field (requires `kv` or `tracing-kv`feature) - Integration with Rust's `tracing` library (requires `tracing` feature) # Usage + ```rust use log::{info, warn}; use pyo3::{ffi::c_str, prelude::*}; @@ -85,21 +90,25 @@ Then you can use Python's `extra` parameter to pass structured data: logging.info("Processing order", extra={"order_id": "12345", "amount": 99.99}) ``` -When using a structured logging subscriber in Rust, these key-value pairs will be properly captured, for example: +When using a structured logging subscriber in Rust, these key-value pairs will +be properly captured, for example: ```bash [2025-03-28T01:12:29Z INFO example_application_py_logger] Processing order order_id=12345 amount=99.99 ``` + ## Tracing Support -To enable integration with Rust's `tracing` library, add the `tracing` feature to your `Cargo.toml`: +To enable integration with Rust's `tracing` library, add the `tracing` feature +to your `Cargo.toml`: ```toml [dependencies] pyo3-pylogger = { version = "0.4", default-features = false, features = ["tracing"] } ``` -When the `tracing` feature is enabled, Python logs will be forwarded to the active tracing subscriber: +When the `tracing` feature is enabled, Python logs will be forwarded to the +active tracing subscriber: ```rust use tracing::{info, warn}; @@ -135,10 +144,17 @@ logging.info('This will be captured by tracing')"# ### Structured Data with Tracing -The `tracing` feature automatically supports Python's `extra` field for structured data. However, the KV fields are json serialized and not available as tracing attributes. This is a limitation of the `tracing` library and is not specific to this crate. See [this issue](https://github.com/tokio-rs/tracing/issues/372) for more information. +The `tracing` feature automatically supports Python's `extra` field for +structured data. However, the KV fields are json serialized and not available as +tracing attributes. This is a limitation of the `tracing` library and is not +specific to this crate. See +[this issue](https://github.com/tokio-rs/tracing/issues/372) for more +information. # Feature Flags -- `kv`: Enables structured logging support via Python's `extra` fields. This adds support for the `log` crate's key-value system. +- `kv`: Enables structured logging support via Python's `extra` fields. This + adds support for the `log` crate's key-value system. - `tracing`: Enables integration with Rust's `tracing` library. -- `tracing-kv`: Enables structured logging support via Python's `extra` fields and integration with Rust's `tracing` library. +- `tracing-kv`: Enables structured logging support via Python's `extra` fields + and integration with Rust's `tracing` library. diff --git a/crates/yt_dlp/src/options.rs b/crates/yt_dlp/src/options.rs index dedb03c..ad30301 100644 --- a/crates/yt_dlp/src/options.rs +++ b/crates/yt_dlp/src/options.rs @@ -170,7 +170,9 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) { // Setup the post processors - let add_post_processor_fun = inner.getattr(intern!(py, "add_post_processor")).wrap_exc(py)?; + let add_post_processor_fun = inner + .getattr(intern!(py, "add_post_processor")) + .wrap_exc(py)?; for pp in options.post_processors { add_post_processor_fun |