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

Change log level of methods name logged in Scaffolding #2136

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Vinnstah
Copy link
Contributor

Fixes #1702

Change the log level to trace for method names logged by UniFFI internals when FFI calls into Rust.

Augmented existing logging tests in Python, asserting that the changed level works as intended.

Let me know if you want me to put the tests in a new fixture instead of recycling an existing one.

@Vinnstah Vinnstah requested a review from a team as a code owner May 29, 2024 18:51
@Vinnstah Vinnstah requested review from mhammond and removed request for a team May 29, 2024 18:51
Copy link
Contributor Author

@Vinnstah Vinnstah left a comment

Choose a reason for hiding this comment

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

Left some clarifying comments.

@@ -1,6 +1,7 @@
[package]
name = "uniffi-fixture-logging-callback-interface"
edition = "2021"
authors = ["Firefox Sync Team <[email protected]>", "Viktor Jansson <[email protected]>"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if you want me to revert this change. I git blamed and saw that Ben has contributed previously, let me know if you want me to add him as well (I think Mark is a member of the sync team?).

Copy link
Member

Choose a reason for hiding this comment

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

Ben's also in the sync team - we'd also be up for removing this line entirely, but until then I think this is fine.

@@ -6,7 +6,7 @@ use std::sync::{Once, RwLock};

// Logger trait that the foreign code implements
pub trait Logger: Sync + Send {
fn log_message(&self, message: String);
fn log_message(&self, message: String, level: String);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

String is more clear than u8, and seems like overkill introducing a UniFFI exported Enum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual fix of #1702

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will make sense when you read test.py...

Copy link
Contributor

@Sajjon Sajjon left a comment

Choose a reason for hiding this comment

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

Nice, I've been waiting for this fix actually, it will be most useful for me in Sargon, where I've recently worked with logging.

@@ -1,6 +1,7 @@
[package]
name = "uniffi-fixture-logging-callback-interface"
edition = "2021"
authors = ["Firefox Sync Team <[email protected]>", "Viktor Jansson <[email protected]>"]
Copy link
Member

Choose a reason for hiding this comment

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

Ben's also in the sync team - we'd also be up for removing this line entirely, but until then I think this is fine.

@@ -285,7 +285,7 @@ pub(super) fn gen_ffi_function(
#[doc(hidden)]
#[no_mangle]
pub extern "C" fn #ffi_ident(#(#param_names: #param_types,)*) -> ::uniffi::Handle {
::uniffi::deps::log::debug!(#name);
::uniffi::deps::log::trace!(#name);
Copy link
Member

Choose a reason for hiding this comment

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

I guess I don't really understand why most of the above changes - ie, I'm not sure how exactly the fixture changes really ensures these 2 lines actually work. Or to put it yet another way, I think I'd r+ this with just these 2 lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

The fixture does not assert one of the changed to trace, the one for async functions.

The logger in the fixture is set to TRACE, and the test asserts that the Method names - the log statement: uniffi::deps::log::trace!(#name); is indeed logged (present in the array of messages - which it also would before this PRs change from debug!(#name).

But then later in the test, the used loggers level is set to debug, and the method name of the subsequent call is not printed (is not in messages). Which it would have been without this PRs change.

So if an async method would be included then this PR, would test the affected source code in full, right?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure what you are saying there, but my point is that unless I'm still missing something, I think the test code here is testing the log crate rather than the uniffi crate?

Copy link
Contributor

Choose a reason for hiding this comment

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

The changed code in the test piggybacks on an existing test, but it does indeed test uniffi crate.

It tests the changed UniFFI source code. Without the changed source code the test would fail.

The test ensures the level at which UniFFI source code logs name of methods is trace.

Copy link
Member

Choose a reason for hiding this comment

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

Without the changed source code the test would fail.

I hope it's clear that I do infact understand that.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Vinnstah I would benefit from this PR getting landed :D

Sounds like Mark would prefer if the changes in the test be reverted, maybe you can revert and this might get merged :)

Copy link
Member

Choose a reason for hiding this comment

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

To be clear, I'm only weakly against tests for this - IMO the value is lower than the cost. But I'm open to be convinced otherwise, and it's difficult to argue too strongly against new tests really :)

@mhammond
Copy link
Member

mhammond commented Jul 3, 2024

Hi, is there any interest in removing some of the test code here? If I don't hear back soon, I'll put up the 2-line PR that actually fixes this and close this, but I'd like to offer the opportunity to have it completed here.

@Vinnstah
Copy link
Contributor Author

Vinnstah commented Jul 7, 2024

Hi Mark,
Apologies for the delay. I'll fix the tests and push a new commit asap.

@praveenperera
Copy link
Contributor

thank you for this! @Vinnstah !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use trace level logging in generated code
4 participants