From 423f80d5d456afe165b61195660d24bc85b4b604 Mon Sep 17 00:00:00 2001 From: zexoverz Date: Wed, 16 Sep 2026 01:06:34 +0700 Subject: [PATCH] Route Rust logs through Python logging via pyo3-log Replaces env_logger with pyo3-log so log records from hypersync-client show up under the hypersync_client logger in Python. Closes #45. --- Cargo.lock | 148 +++++++---------------------------------------------- Cargo.toml | 2 +- README.md | 13 +++++ src/lib.rs | 5 +- 4 files changed, 36 insertions(+), 132 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf50cbf..8553c85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -191,61 +191,20 @@ dependencies = [ ] [[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" +name = "anyhow" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys 0.61.2", -] +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] -name = "anstyle-wincon" -version = "3.0.11" +name = "arc-swap" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys 0.61.2", + "rustversion", ] -[[package]] -name = "anyhow" -version = "1.0.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" - [[package]] name = "ark-ff" version = "0.3.0" @@ -857,12 +816,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "colorchoice" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" - [[package]] name = "const-hex" version = "1.18.1" @@ -1225,29 +1178,6 @@ dependencies = [ "syn 2.0.117", ] -[[package]] -name = "env_filter" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a1c3cc8e57274ec99de65301228b537f1e4eedc1b8e0f9411c6caac8ae7308f" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2daee4ea451f429a58296525ddf28b45a3b64f1acf6587e2067437bb11e218d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "jiff", - "log", -] - [[package]] name = "equivalent" version = "1.0.2" @@ -1743,7 +1673,6 @@ dependencies = [ "alloy-primitives", "anyhow", "arrow", - "env_logger", "faster-hex", "hypersync-client", "mimalloc", @@ -1751,6 +1680,7 @@ dependencies = [ "prefix-hex", "pyo3", "pyo3-async-runtimes", + "pyo3-log", "ruint", "serde", "serde_json", @@ -2035,12 +1965,6 @@ dependencies = [ "serde", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - [[package]] name = "itertools" version = "0.10.5" @@ -2065,30 +1989,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" -[[package]] -name = "jiff" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359" -dependencies = [ - "jiff-static", - "log", - "portable-atomic", - "portable-atomic-util", - "serde_core", -] - -[[package]] -name = "jiff-static" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.117", -] - [[package]] name = "jobserver" version = "0.1.34" @@ -2397,12 +2297,6 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - [[package]] name = "openssl-probe" version = "0.2.1" @@ -2538,15 +2432,6 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" -[[package]] -name = "portable-atomic-util" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" -dependencies = [ - "portable-atomic", -] - [[package]] name = "potential_utf" version = "0.1.4" @@ -2705,6 +2590,17 @@ dependencies = [ "pyo3-build-config", ] +[[package]] +name = "pyo3-log" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64083bd3a16a353d9d62335808e8e13d0552d2a2b83fdb084496192dcfa9fcd" +dependencies = [ + "arc-swap", + "log", + "pyo3", +] + [[package]] name = "pyo3-macros" version = "0.26.0" @@ -3923,12 +3819,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "uuid" version = "1.22.0" diff --git a/Cargo.toml b/Cargo.toml index 0233c38..72314a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ hypersync-client = "1.4.1" anyhow = "1" arrow = { version = "57", features = ["ffi"] } prefix-hex = "0.7" -env_logger = "0.11" +pyo3-log = "0.13" faster-hex = "0.9" ruint = "1" num-bigint = "0.4" diff --git a/README.md b/README.md index c41c9c0..5c23753 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,19 @@ export ENVIO_API_TOKEN="your-token-here" python examples/simple_logs_of_event.py ``` +## Logging + +The Rust core emits its logs through Python's `logging` module, so the usual handlers, formatters and levels apply. Records from the client arrive under the `hypersync_client` logger (HTTP internals arrive under `reqwest`): + +```python +import logging + +logging.basicConfig(level=logging.INFO) +logging.getLogger("hypersync_client").setLevel(logging.DEBUG) +``` + +Configure logging before the first client call. Log levels are cached on the Rust side once a record has been emitted, so changes made later may not take effect. + ## What you can build The Python client is a natural fit for data science workflows, analytics pipelines, and any application that needs fast access to blockchain data from Python: diff --git a/src/lib.rs b/src/lib.rs index 0f7e20f..df261c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,9 @@ use types::RateLimitInfo; #[pymodule] fn hypersync(m: &Bound<'_, PyModule>) -> PyResult<()> { + // Forward Rust `log` records to Python's `logging` module. + pyo3_log::try_init().ok(); + m.add_class::()?; m.add_class::()?; m.add_class::()?; @@ -51,8 +54,6 @@ impl HypersyncClient { /// Create a new client with given config #[new] fn new(config: ClientConfig) -> Result { - env_logger::try_init().ok(); - let config = config.try_convert().context("parse config")?; // Identify this client (and its version) to the server. `hscp` =