Skip to content

Commit

Permalink
python: Enable trace logging
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Nov 6, 2024
1 parent 2cdaf51 commit 28b1c75
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lakers-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ impl AutoCredential {
// this name must match `lib.name` in `Cargo.toml`
#[pymodule]
#[pyo3(name = "lakers")]
fn lakers_python(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
fn lakers_python(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
// initialize the logger once when the module is imported
if !pyo3_log::try_init().is_ok() {
if let Err(e) = pyo3_log::Logger::new(py, pyo3_log::Caching::LoggersAndLevels)?
.filter(log::LevelFilter::Trace)
.install()
{
// 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?)");
log::error!("lakers-python failed to set up: {e}");
}

m.add_function(wrap_pyfunction!(p256_generate_key_pair, m)?)?;
Expand All @@ -91,7 +94,7 @@ fn lakers_python(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<ead_authz::PyAuthzEnrollmentServer>()?;
m.add_class::<ead_authz::PyAuthzServerUserAcl>()?;

let submodule = PyModule::new_bound(_py, "consts")?;
let submodule = PyModule::new_bound(py, "consts")?;
submodule.add("EAD_AUTHZ_LABEL", lakers_ead_authz::consts::EAD_AUTHZ_LABEL)?;
m.add_submodule(&submodule)?;
Ok(())
Expand Down

0 comments on commit 28b1c75

Please sign in to comment.