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

Improve default logger for realm/react #5698

Closed
wants to merge 1 commit into from

Conversation

takameyer
Copy link
Contributor

What, How & Why?

The default logger could be a bit smarter. This will print a contextual log message with the level and use either console.error, console.warn and console.log based on the relevant level. This also sets a default log level to WARN.

☑️ ToDos

  • 📝 Changelog entry
  • 📝 Compatibility label is updated or copied from previous entry
  • 📝 Update COMPATIBILITY.md
  • 🚦 Tests
  • 🔀 Executed flexible sync tests locally if modifying flexible sync
  • 📦 Updated internal package version in consuming package.jsons (if updating internal packages)
  • 📱 Check the React Native/other sample apps work if necessary
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

If this PR adds or changes public API's:

  • typescript definitions file is updated
  • jsdoc files updated

The defaul tlogger could be a bit smarter.  This will print a contextual log message
with the level and use either `console.error`, `console.warn` and `console.log` based on the relevant level.  This also sets a default log level to WARN.
@kraenhansen
Copy link
Member

Why not add this to the realm package directly? I think a good default logger would be valuable more generally.

@takameyer
Copy link
Contributor Author

takameyer commented Apr 5, 2023

Why not add this to the realm package directly?

I've wanted to do this for a while, so I have no argument against not doing it directly.
Also, I'm pretty sure @papafe is going to do this with the unified logger. This is to help people using React Native and Realm today.

@kraenhansen
Copy link
Member

I see. If @papafe is already solving this for v12 with the unified logger, (btw, what issue is is tracking that?), I'd suggest holding back on this, as we want to be sure loading @realm/react won't override the default he'll be implementing, right?

@takameyer
Copy link
Contributor Author

takameyer commented Apr 5, 2023

@realm/react won't override the default

The unified logger will be at a different entry point and this would turn into a no-op. So this will just be backwards compatible. I want to still ensure v11 users get the advantages of the @realm/react updates.

what issue is is tracking that?

Unified Logger Issue

@kraenhansen
Copy link
Member

As I read the last comment on the unified logger issue, the Realm.App.Sync.setLogger will change to call Realm.setLogger and with this PR merged @realm/react will override whatever default the realm package injects on import, right? What am I missing? To me this change will interfere with the future default behavior of realm@v12.

@takameyer
Copy link
Contributor Author

takameyer commented Apr 6, 2023

@kraenhansen How would you recommend we support both versions of logging? With this change, users wouldn't even have to update realm to get default logger. After unified logging is realised, we can make this support both.

Realm.App.Sync.setLogger will change to call Realm.setLogger

This will be a breaking change then right? We should probably make unified logging a v13 change if Realm.App.Sync.setLogger doesn't work anymore.

Copy link
Contributor

@kneth kneth left a comment

Choose a reason for hiding this comment

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

My comment is only minor (mostly enhancing readability) and can be ignored

// Since the logger provides the numeric log level, we need to convert it to a
// string for the log message.
const getLogLevelString = (level: Realm.App.Sync.NumericLogLevel) => {
switch (level) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use an object literal? And let it default to DEFALT_LOG_LEVEL?

Copy link
Contributor

@elle-j elle-j left a comment

Choose a reason for hiding this comment

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

I like the split off the various console methods! (Apologies for late review, this went under my radar)


// Since the logger provides the numeric log level, we need to convert it to a
// string for the log message.
const getLogLevelString = (level: Realm.App.Sync.NumericLogLevel) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

NumericLogLevel.All and NumericLogLevel.Off as well 👍

@takameyer
Copy link
Contributor Author

I may be closing this, as the effort @papafe is currently doing will probably nullify this, as well as the logLevel and logger properties of the AppProvider. Part of me does want to release this, just so people that haven't updated to v12 can reap the benefits, although I'm unsure if this comes into conflict with the recent core versions.

@kraenhansen kraenhansen marked this pull request as draft May 9, 2023 08:22
@takameyer takameyer closed this Jun 19, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 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.

4 participants