Skip to content

fix(ffi): ensure there's always a global directive for logs #4485

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

Merged
merged 2 commits into from
Jan 8, 2025
Merged
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
16 changes: 15 additions & 1 deletion bindings/matrix-sdk-ffi/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,23 @@ pub struct TracingConfiguration {
}

#[matrix_sdk_ffi_macros::export]
pub fn setup_tracing(config: TracingConfiguration) {
pub fn setup_tracing(mut config: TracingConfiguration) {
log_panics();

// If there's no global directive, and a non-empty set of module/crate
// directives, then logs from modules and crates *not* appearing in the list
// of directives will be silently swallowed. This is bad, especially at the
// `error` level, for which we always want to see logs (notably because the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original reason for removing the global directive is to take zero chances that a 3rd party crate would log sensitive data, which would be hard to find and even harder to clean up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good point. I've implemented your suggestion to restrict this to only adding panic=error to the log filter line, since it's a more cautious choice.

// panic logger uses the error level and a target that may not be specified in
// the list of user-provided directives).
//
// As a result, always make sure there's a global directive. If it's not there,
// we insert it at the beginning of the filter line.

if !config.filter.split(',').any(|pair| !pair.contains('=')) {
config.filter = "error,".to_owned() + config.filter.as_str();
}

tracing_subscriber::registry()
.with(EnvFilter::new(&config.filter))
.with(text_layers(config))
Expand Down
Loading