Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: Use Python's logging through pyo3_log #319

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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