Skip to content

Commit

Permalink
python: Use Python's logging through pyo3_log
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Nov 3, 2024
1 parent a11fe34 commit 2cdaf51
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lakers-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lakers-ead-authz = { path = "../ead/lakers-ead-authz", features = [ "log" ] }
lakers-shared = { path = "../shared", features = ["python-bindings", "quadruple_sizes"] }
lakers-crypto = { path = "../crypto", default-features = false, features = ["rustcrypto"] }
log = "0.4"
env_logger = "0.9"
pyo3-log = "0.11.0"

[dev-dependencies]
# We don't need it to build, but it is listed in the manifest Cargo.toml, and
Expand Down
7 changes: 4 additions & 3 deletions lakers-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/// Note that this module is not restricted by no_std.
use lakers::*;
// use lakers_ead_authz::consts::*;
use env_logger;
use lakers_crypto::{default_crypto, CryptoTrait};
use log::trace;
use pyo3::wrap_pyfunction;
Expand Down Expand Up @@ -72,8 +71,10 @@ impl AutoCredential {
#[pyo3(name = "lakers")]
fn lakers_python(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
// initialize the logger once when the module is imported
if env_logger::try_init().is_ok() {
trace!("lakers-python initialized from Rust side.");
if !pyo3_log::try_init().is_ok() {
// Not logging anything in the successful case as per pyo3_log recommendations: That would
// cache the current logging configuration, which likely changes soon after the imports.
log::error!("lakers-python failed to set up (different logger configured?)");
}

m.add_function(wrap_pyfunction!(p256_generate_key_pair, m)?)?;
Expand Down

0 comments on commit 2cdaf51

Please sign in to comment.