-
-
Notifications
You must be signed in to change notification settings - Fork 916
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
feat: Add global logger object #1222
base: main
Are you sure you want to change the base?
Conversation
@MilanKovacic here's the drafted PR for the global logging feature. It is complete and contains 12 new unit tests. All the new tests are passing. As seen in the PR, all previous unit testing related to console writing pass without modification, which should be a testament of the neutral nature of the change. This change is fully backwards compatible. Please review and let me know if any changes are needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of small things. Thanks @webJose!
Changes applied! |
Changes made. Additionally, I created the corresponding PR in the documentation website. |
@webJose Can you mark this as no longer a draft? @MilanKovacic what do you think about merging this? |
Motivation
I personally would like to remove minified error message 1 (see #1161), and others have expressed their desire to completely suppress logging.
With this solution, both are possible.
How It Works
A new utility module named
logging
has been added to thesrc/utils
folder that exports 2 objects:setLogger()
function that controls the destination of all log entries.logger
object, whose methods write to the log destination set bysetLogger()
.By default, the log destination is the console. Users can, at any point in their application's lifecycle, call
setLogger()
to control which log entries make it to the browser's console.setLogger()
This function takes 1 argument that can be
false
,true
or a custom destination log object.The value
false
internally sets a log destination that discards all messages; the valuetrue
routes all messages to the console. The third option allows the caller to take complete control over what to do with the logged messages.For Maintainers and Contributors
Never do
console.debug()
,console.info()
,console.warn()
orconsole.error()
ever again. Always replaceconsole
withlogger
. Logger is imported: