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 issues with Logging module ('kolibri.lib.logging') #11820

Merged
merged 5 commits into from
Feb 23, 2024

Conversation

iskipu
Copy link
Contributor

@iskipu iskipu commented Jan 30, 2024

This PR fixes both the issues mentioned in #11819 and also it fixes #11821 (the reason why the modal is not closing is because the logging module's .log method was not working in the below mentioned lines in the code base

logging.log('mounted', isMetered);
logging.log(data);

)

I hope this changes solves the issue.

Fixes #11819, fixes #11821

Results:

Image (after making .log function work)
image
Image (after making .setLevel function work)
image

@MisRob MisRob added the TODO: needs review Waiting for review label Jan 30, 2024
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

The logging module isn't broken. The call should be info not log. Please update the broken reference instead.

@iskipu
Copy link
Contributor Author

iskipu commented Jan 30, 2024

The logging module isn't broken. The call should be info not log. Please update the broken reference instead.

Hi @rtibbles since logging.js is a wrapper around npm module loglevel i thought it would be better if it directly supports .log function just like loglevel as (mentioned here), Plz take a look at it and if u think its not necessary i will just make changes to the reference directly.

and also any comments/suggestions regarding .setLevel function ?

@iskipu iskipu closed this Jan 30, 2024
@iskipu iskipu reopened this Jan 30, 2024
@iskipu iskipu requested a review from rtibbles January 30, 2024 16:28
@rtibbles
Copy link
Member

It's there as an alias for debug, so if the intention is to debug then debug should be used (although this seems unintuitive because console.log is functionally more equivalent to the info method), so I don't want to expose this.

@rtibbles
Copy link
Member

I haven't looked closely at the setLevel issue. If it's not working that's a bug in loglevel.

@iskipu
Copy link
Contributor Author

iskipu commented Jan 30, 2024

It's there as an alias for debug, so if the intention is to debug then debug should be used (although this seems unintuitive because console.log is functionally more equivalent to the info method), so I don't want to expose this.

Ohk Understood, i changed the .log to .info in MeteredConnectionNotificationModal.vue like u suggested this closes #11821

@iskipu
Copy link
Contributor Author

iskipu commented Jan 30, 2024

I haven't looked closely at the setLevel issue. If it's not working that's a bug in loglevel.

I did check, this its not a bug in loglevel
Headsup: my explanation might be very bad 😅

the problem is that in loglevel module .debug, .info, .error ... this functions get generated dynamically based on the value of level set by setLevel (refer this link)

and in our code base the following line is defined which directy uses the function (lets say x) at that point (i.e when setLevel is 3 (default value)) but since as i mentioned earlier that the functions are generated dynamically we are stuck with x even after changing the level with the help of setLevel.

this[name] = logFunction.bind(console, this.messagePrefix(name));

Inorder to fix this i proposed this changes

      this[name] = param => {
          return this.logger[name].bind(console, this.messagePrefix(name))(param);
        };

Sorry if my explanation is bad i hope it made some sense let me know if i am doing something wrong.

@rtibbles
Copy link
Member

Yes, you're right - it seems since this was first implemented, loglevel has implemented a plugin interface, with a specific example of adding a prefix to log statements.

I think the best thing to do would be to use this example to update the code, rather than binding to the global console!

https://npmjs.com/package/loglevel#writing-plugins

@rtibbles rtibbles self-assigned this Jan 31, 2024
@iskipu
Copy link
Contributor Author

iskipu commented Jan 31, 2024

I think the best thing to do would be to use this example to update the code, rather than binding to the global console!

Hi @rtibbles great idea, made a new commit with ur suggestion.

@iskipu iskipu requested a review from rtibbles February 1, 2024 13:29
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

This looks good to go, thanks @iskipu - I am going to defer merging this until after we have released 0.16.0, as the metered connection modal is not currently active in any of our products, and we are only merging critical bug fixes at this time. We should be able to merge this in a few weeks!

@rtibbles rtibbles added this to the Kolibri 0.16: Planned Patch 1 milestone Feb 1, 2024
@rtibbles rtibbles merged commit 3a28d76 into learningequality:release-v0.16.x Feb 23, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants