-
-
Notifications
You must be signed in to change notification settings - Fork 929
feat: Add global logger object #1222
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
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. |
ibacher
left a comment
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? |
|
This adds complexity and increases single-spa's API surface while providing little value. Logging to the console is ok. For comparison, ReactJS logs warnings to the console. Not calling I'm closing this because I don't support the feature being added to single-spa |
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
logginghas been added to thesrc/utilsfolder that exports 2 objects:setLogger()function that controls the destination of all log entries.loggerobject, 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,trueor a custom destination log object.The value
falseinternally sets a log destination that discards all messages; the valuetrueroutes 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 replaceconsolewithlogger. Logger is imported: