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

RCOCOA-2399: Add support for Logger categories/ Improve current logger. #8608

Merged
merged 8 commits into from
Jun 29, 2024

Conversation

dianaafanador3
Copy link
Contributor

@dianaafanador3 dianaafanador3 commented May 27, 2024

  • Added support for filtering logs by category. Users wil have more fine grained control over
    the log level for each category as well.
    Logger.setLogLevel(.info, for: Category.Storage.transactions)

This has a proposal for the Categories enum which includes nested categories, for Objective-C we are using strings as it may be very complicated to have nested enums and it may be too mucho work for the number of users using Objective-C

@cla-bot cla-bot bot added the cla: yes label May 27, 2024
@dianaafanador3 dianaafanador3 marked this pull request as ready for review May 27, 2024 22:17
Copy link
Member

@tgoyne tgoyne left a comment

Choose a reason for hiding this comment

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

I don't see any reason for the obj-c code to be using strings for category names. There's a fixed set of them, so it can just be a (non-nested) enum.

Realm/RLMLogger.h Outdated Show resolved Hide resolved
Realm/RLMLogger.mm Outdated Show resolved Hide resolved
Realm/RLMLogger.mm Outdated Show resolved Hide resolved
Realm/RLMLogger.mm Outdated Show resolved Hide resolved
Realm/RLMSyncManager.mm Outdated Show resolved Hide resolved
- parameter category: The log category for the message.
- parameter message: The message to log.
*/
internal func log(level: LogLevel, category: LogCategory = Category.realm, message: String) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this here?

Copy link
Contributor Author

@dianaafanador3 dianaafanador3 May 31, 2024

Choose a reason for hiding this comment

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

This is just makes it easier for us internally to log in the SDK side, we do have a category for this kind of logs Category.sdk in Swift

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is also a category for app logs Category.app, so we could expose this to the user in that matters, but I agree that we don't need to expose this to the users and add noise to our logging mechanism, but I do agree that we could have some logging in the sdk side, we should discuss how granular we want this because we don't want to contaminate Core's log

RealmSwift/Logger.swift Outdated Show resolved Hide resolved
RealmSwift/Logger.swift Outdated Show resolved Hide resolved
@dianaafanador3 dianaafanador3 force-pushed the dp/improve-logging-categories branch 3 times, most recently from 1472ad6 to 02913a7 Compare May 30, 2024 16:14
Realm/RLMLogger_Private copy.h Outdated Show resolved Hide resolved
Realm/RLMLogger_Private.h Outdated Show resolved Hide resolved
Copy link

@clementetb clementetb left a comment

Choose a reason for hiding this comment

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

The current logger implementation does not filter per category as per the documentation.

Realm/RLMLogger.mm Outdated Show resolved Hide resolved
}

- (instancetype)initWithLevel:(RLMLogLevel)level
category:(RLMLogCategory)category

Choose a reason for hiding this comment

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

The loggers created with this function are of the default category realm. If you like to filter by category you might need to instantiate a Logger with the category.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the approach, and now you can only set the global log level for a category using setLogLevel. initWithLevel is gonna is deprecated

Copy link

@clementetb clementetb left a comment

Choose a reason for hiding this comment

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

LGTM

@dianaafanador3 dianaafanador3 force-pushed the dp/improve-logging-categories branch 3 times, most recently from ee66e9c to fea2867 Compare June 25, 2024 09:09
Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Looks good - I only have minor comments/suggestions.

CHANGELOG.md Outdated Show resolved Hide resolved
Realm/RLMLogger.h Outdated Show resolved Hide resolved
Realm/RLMLogger.h Outdated Show resolved Hide resolved
Realm/RLMLogger.mm Outdated Show resolved Hide resolved
Realm/Tests/SwiftUISyncTestHost/ContentView.swift Outdated Show resolved Hide resolved
RealmSwift/Logger.swift Show resolved Hide resolved
RealmSwift/Logger.swift Outdated Show resolved Hide resolved
RealmSwift/Logger.swift Outdated Show resolved Hide resolved
RealmSwift/Tests/RealmTests.swift Show resolved Hide resolved
XCTAssertTrue(logs.value.contains("Transaction test entry"))
logs.wrappedValue = ""

logger.log(with: .info, categoryName: Category.realm.rawValue, message: "REALM test entry")
Copy link
Member

Choose a reason for hiding this comment

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

Why is this passing the raw category name rather than the LogCategory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we cannot expose internal function to the test suite, instead we are using Realm.Private API to generate the logs for the tests

@dianaafanador3 dianaafanador3 linked an issue Jun 26, 2024 that may be closed by this pull request
*/
typedef NS_ENUM(NSUInteger, RLMLogCategory) {
/// Top level log category for Realm, updating this category level would set all other subcategories too.
RLMLogCategoryRealm,
Copy link
Member

Choose a reason for hiding this comment

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

[nit] This naming scheme is causing a bit of tautology as we have the RLM prefix and the Realm suffix/infix. One option would be to have

RLMLogCategoryAll,
RLMLogCategorySDK,
...

Essentially dropping the Realm as it's part of every category, thus not bringing any new information. Not a blocker though.

Copy link
Contributor Author

@dianaafanador3 dianaafanador3 Jun 28, 2024

Choose a reason for hiding this comment

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

Should we change RLMLogCategoryRealm as well?, given that this is the keyword we use for this categories in all SDKs?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I feel a bit ambiguous about it - I'd be fine with either keeping it as RLMLogCategoryRealm or with replacing it with RLMLogCategoryAll. I think in other SDKs we can get away with it because we don't have the RLM prefix (similarly to what we do in Swift). That being said, perhaps we shouldn't overthink it as Obj C users are so few and whether we have Realm in there or not is unlikely to make a huge difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Swift we have Category.realm so to keep uniformity in both APIs, we can keep it like that, and then remove Realm for the rest of the categories

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added changes

@dianaafanador3 dianaafanador3 merged commit 9f850cb into master Jun 29, 2024
129 of 133 checks passed
@dianaafanador3 dianaafanador3 deleted the dp/improve-logging-categories branch June 29, 2024 12:54
@dianaafanador3 dianaafanador3 changed the title RCOCOA-2273: Add support for Logger categories/ Improve current logger. RCOCOA-2399: Add support for Logger categories/ Improve current logger. Jul 1, 2024
dianaafanador3 added a commit that referenced this pull request Jul 22, 2024
dianaafanador3 added a commit that referenced this pull request Jul 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 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.

Add support for logging categories
4 participants