matrix-org / matrix-org/matrix-rust-sdk

Extend the logging callback interface in matrix-sdk-crypto-ffi

Open
#1,759 0 comments 0 reactions 0 assignees View on GitHub
bindings good first issue
Dominant language
Rust
Stars
2.3k
Forks
500
Avg merge
1d 16h
Merged PRs (30d)
106

Description

The `matrix-sdk-crypto-ffi` crate allows users to forward native Rust logs to their own logger of choice.

This is achieved using `uniffi` [callback interfaces](https://mozilla.github.io/uniffi-rs/udl/callback_interfaces.html). One problem with our current solution is that we're only allowing users to set a single method for the logger.

No matter which level a log line has, it has to use the same log level on the other side of the FFI. An additional problem is that the structured data gets merged into the message.

The code in question can be found here:
https://github.com/matrix-org/matrix-rust-sdk/blob/b033508e9bbf6eafa2eaac174ea412cc97a2c640/bindings/matrix-sdk-crypto-ffi/src/logger.rs#L8-L15

We need to extend this and expose multiple methods, one per log level and pass the structured data separately :

```rust
/// Trait that can be used to forward Rust logs over FFI to a language specific
/// logger.
pub trait Logger: Send {
/// Called every time the Rust side wants to post a log line.
fn log_debug(&self, message: String, data: String);
fn log_info(&self, message: String, data: String);
...
fn log_error(&self, message: String, data: String);
}
```

Contributor guide

Open the contributing guide

Research direction

Start in bindings/matrix-sdk-crypto-ffi/src/logger.rs at the callback interface described in the issue, then review the linked uniffi callback-interface documentation. Expose one logger method per log level and keep structured data separate from the message; verify that the resulting interface forwards each level and both values over FFI.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.