Fix Node.js v25 logging prefix and modernize logger#4049
Merged
rejas merged 4 commits intoMagicMirrorOrg:developfrom Mar 6, 2026
Merged
Fix Node.js v25 logging prefix and modernize logger#4049rejas merged 4 commits intoMagicMirrorOrg:developfrom
rejas merged 4 commits intoMagicMirrorOrg:developfrom
Conversation
…n logger The previous approach set Error.prepareStackTrace after creating the Error object, which is fragile and relies on lazy evaluation of err.stack. Replace with direct string parsing of new Error().stack using a regex, which is simpler and more robust across Node.js versions.
Node.js v25 removed "grey" as a valid color name for styleText(). Only "gray" is accepted. This caused styleText() to throw inside the pre token callback, which console-stamp silently caught and returned the raw ":pre()" format string as the prefix. Fixes MagicMirrorOrg#4048
The UMD (Universal Module Definition) wrapper was unnecessary overhead. The logger only ever needs to run in two environments: Node.js (CJS) and the browser (global). Replace with a plain IIFE that checks typeof module directly. Also removes the unused 'config' parameter that was passed through the UMD factory but never referenced inside it.
Remove the console-stamp dependency and replicate its behavior directly using Node.js built-ins only (node:util styleText). Also clean up the new implementation: - Fix regex bug: unescaped dot in .js patterns (. → \.) - Rename confusing variables: filename/filepath → baseName/parentDir - Split formatTimestamp into readable date/time variables - Update outdated top comment
rejas
approved these changes
Mar 6, 2026
khassel
pushed a commit
that referenced
this pull request
Mar 6, 2026
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 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.
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.
On Node.js v25, the log prefix in the terminal stopped working - instead of seeing something like:
the output was:
Reported in #4048.
Why did it break?
The logger used the
console-stamppackage to format log output. One part of that formatting usedstyleText("grey", ...)to color the caller prefix gray. Node.js v25 dropped"grey"as a valid color name (only"gray"with an "a" is accepted now). This causedstyleTextto throw an error internally - andconsole-stampsilently swallowed that error and fell back to returning its raw:pre()format string as the prefix. Not ideal.What's in this PR?
1. The actual fix -
"grey"→"gray".2. Cleaner stack trace approach - the previous code set
Error.prepareStackTraceafter creating theError, which is fragile and was starting to behave differently across Node versions. Replaced with straightforward string parsing ofnew Error().stack.3. Removed the
console-stampdependency - all formatting is now done with plain Node.js built-ins (node:utilstyleText). Same visual result, no external dependency.4. Simplified the module wrapper - the logger was wrapped in a UMD pattern, which is meant for environments like AMD/RequireJS. MagicMirror only runs in two places: Node.js and the browser. Replaced with a simple check (
typeof module !== "undefined"), which is much easier to follow.