Skip to content

Commit

Permalink
python: Enable trace logging, add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Nov 6, 2024
1 parent 28b1c75 commit 96e0286
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lakers-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,25 @@ impl AutoCredential {
}
}

// this name must match `lib.name` in `Cargo.toml`
/// Lakers implementation of EDHOC.
///
/// The `EdhocInitiator` and `EdhocResponder` are entry points to this module.
///
/// Operations in this module produce logging entries on the `lakers.initiator` and
/// `lakers.responder` logger names. Due to implementation details of `pyo3_log`, Python's log
/// levels are cached in the Rust implementation. It is recommended that the full logging
/// is configured before creating Lakers objects. A setup with `logging.basicConfig(loglevel=5)`
/// will also show Lakers' trace level log messages, which have no equivalent Python level.
#[pymodule]
// this name must match `lib.name` in `Cargo.toml`
#[pyo3(name = "lakers")]
fn lakers_python(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
// initialize the logger once when the module is imported
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.
// Not logging anything in the successful case (see module level docs)
log::error!("lakers-python failed to set up: {e}");
}

Expand Down

0 comments on commit 96e0286

Please sign in to comment.