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-2273: Add support for Logger categories/ Improve current logger. #8608

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dianaafanador3
Copy link
Collaborator

@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
Collaborator 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
Collaborator 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
Collaborator 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 2 times, most recently from 7a6d55f to ee66e9c Compare June 24, 2024 21:14
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
Collaborator 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for logging categories
4 participants