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

Fix RealmLog does not log sync events #1459

Merged
merged 4 commits into from
Jul 21, 2023

Conversation

clementetb
Copy link
Contributor

@clementetb clementetb commented Jul 20, 2023

Sync events are not logged when RealmLog.level is set. Any level previously defined is ignored, except if it is defined via the deprecated AppConfiguration.Builder.log.

The reason the level is ignored is because whenever an App or Realm configuration is set the log level is set to a default level of WARN.

This PR fixes the issue by setting the default level to the RealmLog.level, this way, if the user does not define any level via the deprecated method, we will set the level to whatever was already defined.

@clementetb clementetb self-assigned this Jul 20, 2023
@cla-bot cla-bot bot added the cla: yes label Jul 20, 2023
@clementetb clementetb marked this pull request as draft July 20, 2023 22:33
@nirinchev
Copy link
Member

nirinchev commented Jul 20, 2023

I don't have any idea how the Kotlin SDK opens apps or defines the logger, but if I understand the issue description correctly, then it must be doing it the wrong way. In the implementation of SyncManager::do_get_logger we can see that the app-supplied log_level is only used if the the log factory on the app configuration is set. If the user didn't specify custom logger/loglevel through the deprecated methods, then the default logger should be used which should ignore any log_level set on the app config.

If the Kotlin SDK does set a logger factory on the app config, even if the user doesn't use the deprecated methods, this is a mistake as it means the app logger will ignore changes to the RealmLog.level (e.g. you create the app with RealmLog.level set to info, but then change it to detail).

Ignore that ^ - we were able to trace it to AppConfiguration.Builder.build overriding the RealmLog.level with whatever is in the builder.

@clementetb
Copy link
Contributor Author

As discussed, this behavior should be possible (but it is not):

RealmLog.level = info;
app = App.create(AppConfig(...));
user = app.login(...);
realm = Realm(FlexibleSyncConfig(user));

// see only info messages

RealmLog.level = debug;

// expect to see debug messages

@clementetb clementetb marked this pull request as ready for review July 20, 2023 23:50
@nirinchev
Copy link
Member

nirinchev commented Jul 21, 2023

I wrote a .NET test to verify the Core behavior is correct and it seems to be. This is the PR: realm/realm-dotnet#3389 and I can see that once I change the log level, I see messages at the new level. So the issue doesn't seem to be from Core (or at least the parts of Core Kotlin and .NET are sharing).

@clementetb
Copy link
Contributor Author

I confirm that it has the right behavior in Kotlin too, I was testing with an app without the latest local snapshot 🤦

@clementetb clementetb merged commit d648dbd into releases Jul 21, 2023
1 check passed
@clementetb clementetb deleted the ct/fix-realm-log-sync-events branch July 21, 2023 11:30
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants