Skip to content

refactor: further logger clean-up#4050

Merged
khassel merged 2 commits intoMagicMirrorOrg:developfrom
KristjanESPERANTO:logger
Mar 6, 2026
Merged

refactor: further logger clean-up#4050
khassel merged 2 commits intoMagicMirrorOrg:developfrom
KristjanESPERANTO:logger

Conversation

@KristjanESPERANTO
Copy link
Collaborator

After #4049 here are two small follow-up improvements to js/logger.js.

1. Simpler bind syntaxFunction.prototype.bind.call(console.debug, console) is an archaic pattern. The equivalent console.debug.bind(console) works fine in all supported engines (Node.js ≥ 22, modern browsers) and is much easier to read. Also: console.timeStamp exists 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 from console[key]. This makes the filtered set obvious at a glance and ensures utility methods like group, time, and timeStamp are never accidentally silenced — they're structural helpers, not log levels.

…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 khassel merged commit e7503a4 into MagicMirrorOrg:develop Mar 6, 2026
9 checks passed
@KristjanESPERANTO KristjanESPERANTO deleted the logger branch March 6, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants