refactor: further logger clean-up#4050
Merged
khassel merged 2 commits intoMagicMirrorOrg:developfrom Mar 6, 2026
Merged
Conversation
…ogger Function.prototype.bind.call(console.x, console) is an archaic pattern needed for very old environments. The equivalent console.x.bind(console) works in all supported engines (Node >= 22, modern browsers). console.timeStamp exists in all supported environments, so the conditional fallback is no longer needed.
Iterate over the five log-level methods (debug, log, info, warn, error) and rebind from console[key] on each call instead of permanently overwriting with an empty function. This also makes the operation reversible. Utility methods (group, groupCollapsed, groupEnd, time, timeEnd, timeStamp) are no longer touched by setLogLevel.
khassel
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After #4049 here are two small follow-up improvements to
js/logger.js.1. Simpler bind syntax —
Function.prototype.bind.call(console.debug, console)is an archaic pattern. The equivalentconsole.debug.bind(console)works fine in all supported engines (Node.js ≥ 22, modern browsers) and is much easier to read. Also:console.timeStampexists in all supported environments, so the conditional fallback to an empty function is no longer needed.2. Simpler
setLogLevel— instead of iterating over all keys in the logger object and permanently overwriting them, the method now loops over the five log-level keys explicitly and rebinds fromconsole[key]. This makes the filtered set obvious at a glance and ensures utility methods likegroup,time, andtimeStampare never accidentally silenced — they're structural helpers, not log levels.