Skip to content

Commit

Permalink
[logging]: send Rust log messages to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Aug 13, 2024
1 parent e193fe1 commit bd65c0a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.22", features = ["extension-module", "abi3-py38", "indexmap", "anyhow"] }
anyhow = "1"
log = "0.4"
pyo3-log = "0.11"
rquest = { version = "0.20", default-features = false, features = [
"boring-tls",
"http2",
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ impl Client {
let url = PyString::new_bound(py, &f_url).unbind();
let content = PyBytes::new_bound(py, &f_buf).unbind();

log::info!("response: {} {} {} {}", f_url, f_status_code, f_buf.len(), f_encoding);

Ok(Response {
content,
cookies,
Expand Down Expand Up @@ -1004,6 +1006,8 @@ fn patch(

#[pymodule]
fn primp(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
pyo3_log::init();

m.add_class::<Client>()?;
m.add_function(wrap_pyfunction!(request, m)?)?;
m.add_function(wrap_pyfunction!(get, m)?)?;
Expand Down

0 comments on commit bd65c0a

Please sign in to comment.