Skip to content

Commit a1c1e95

Browse files
rejasveeck
andauthored
[logger] Add prefixes to most Log messages (#3923)
Co-authored-by: veeck <[email protected]>
1 parent f1c0c38 commit a1c1e95

34 files changed

+220
-238
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ planned for 2026-01-01
2929
### Updated
3030

3131
- [core] Update dependencies (#3909, #3916, #3921, #3925)
32+
- [logger] Add prefixes to most Log messages (#3923)
3233

3334
## [2.33.0] - 2025-10-01
3435

@@ -358,7 +359,7 @@ For more info, please read the following post: [A New Chapter for MagicMirror: T
358359
### Fixed
359360

360361
- [weather] Correct apiBase of weathergov weatherProvider to match documentation (#2926)
361-
- Worked around several issues in the RRULE library that were causing deleted calender events to still show, some
362+
- Worked around several issues in the RRULE library that were causing deleted calendar events to still show, some
362363
initial and recurring events to not show, and some event times to be off an hour. (#3291)
363364
- Skip changelog requirement when running tests for dependency updates (#3320)
364365
- Display precipitation probability when it is 0% instead of blank/empty (#3345)

js/animateCSS.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function addAnimateCSS (element, animation, animationTime) {
132132
const node = document.getElementById(element);
133133
if (!node) {
134134
// don't execute animate: we don't find div
135-
Log.warn("addAnimateCSS: node not found for", element);
135+
Log.warn("[animateCSS] node not found for adding", element);
136136
return;
137137
}
138138
node.style.setProperty("--animate-duration", `${animationTime}s`);
@@ -149,7 +149,7 @@ function removeAnimateCSS (element, animation) {
149149
const node = document.getElementById(element);
150150
if (!node) {
151151
// don't execute animate: we don't find div
152-
Log.warn("removeAnimateCSS: node not found for", element);
152+
Log.warn("[animateCSS] node not found for removing", element);
153153
return;
154154
}
155155
node.classList.remove("animate__animated", animationName);

js/check_config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function checkConfigFile () {
4444
}
4545

4646
// Validate syntax of the configuration file.
47-
Log.info(`Checking config file ${configFileName} ...`);
47+
Log.info(`[checkconfig] Checking config file ${configFileName} ...`);
4848

4949
// I'm not sure if all ever is utf-8
5050
const configFile = fs.readFileSync(configFileName, "utf-8");
@@ -67,7 +67,7 @@ function checkConfigFile () {
6767
);
6868

6969
if (errors.length === 0) {
70-
Log.info(styleText("green", "Your configuration file doesn't contain syntax errors :)"));
70+
Log.info(styleText("green", "[checkconfig] Your configuration file doesn't contain syntax errors :)"));
7171
validateModulePositions(configFileName);
7272
} else {
7373
let errorMessage = "Your configuration file contains syntax errors :(";
@@ -84,7 +84,7 @@ function checkConfigFile () {
8484
* @param {string} configFileName - The path and filename of the configuration file to validate.
8585
*/
8686
function validateModulePositions (configFileName) {
87-
Log.info("Checking modules structure configuration ...");
87+
Log.info("[checkconfig] Checking modules structure configuration ...");
8888

8989
const positionList = Utils.getModulePositions();
9090

@@ -118,7 +118,7 @@ function validateModulePositions (configFileName) {
118118

119119
const valid = validate(data);
120120
if (valid) {
121-
Log.info(styleText("green", "Your modules structure configuration doesn't contain errors :)"));
121+
Log.info(styleText("green", "[checkconfig] Your modules structure configuration doesn't contain errors :)"));
122122
} else {
123123
const module = validate.errors[0].instancePath.split("/")[2];
124124
const position = validate.errors[0].instancePath.split("/")[3];
@@ -130,13 +130,13 @@ function validateModulePositions (configFileName) {
130130
} else {
131131
errorMessage += validate.errors[0].message;
132132
}
133-
Log.error(errorMessage);
133+
Log.error("[checkconfig]", errorMessage);
134134
}
135135
}
136136

137137
try {
138138
checkConfigFile();
139139
} catch (error) {
140-
Log.error(error.message);
140+
Log.error("[checkconfig]", error);
141141
process.exit(1);
142142
}

js/electron.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function createWindow () {
4040
try {
4141
electronSize = electron.screen.getPrimaryDisplay().workAreaSize;
4242
} catch {
43-
Log.warn("Could not get display size, using defaults ...");
43+
Log.warn("[electron] Could not get display size, using defaults ...");
4444
}
4545

4646
let electronSwitchesDefaults = ["autoplay-policy", "no-user-gesture-required"];
@@ -196,7 +196,7 @@ app.on("activate", function () {
196196
* core.stop() is called by process.on("SIGINT"... in `app.js`
197197
*/
198198
app.on("before-quit", async (event) => {
199-
Log.log("Shutting down server...");
199+
Log.log("[electron] Shutting down server...");
200200
event.preventDefault();
201201
setTimeout(() => {
202202
process.exit(0);
@@ -215,7 +215,7 @@ app.on("certificate-error", (event, webContents, url, error, certificate, callba
215215

216216
if (process.env.clientonly) {
217217
app.whenReady().then(() => {
218-
Log.log("Launching client viewer application.");
218+
Log.log("[electron] Launching client viewer application.");
219219
createWindow();
220220
});
221221
}
@@ -228,7 +228,7 @@ if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].includes(co
228228
core.start().then((c) => {
229229
config = c;
230230
app.whenReady().then(() => {
231-
Log.log("Launching application.");
231+
Log.log("[electron] Launching application.");
232232
createWindow();
233233
});
234234
});

js/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ const MM = (function () {
268268
const hideModule = function (module, speed, callback, options = {}) {
269269
// set lockString if set in options.
270270
if (options.lockString) {
271-
// Log.log("Has lockstring: " + options.lockString);
272271
if (module.lockStrings.indexOf(options.lockString) === -1) {
273272
module.lockStrings.push(options.lockString);
274273
}

js/module.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const Module = Class.extend({
3838
* Called when the module is instantiated.
3939
*/
4040
init () {
41-
//Log.log(this.defaults);
4241
},
4342

4443
/**
@@ -145,9 +144,9 @@ const Module = Class.extend({
145144
*/
146145
notificationReceived (notification, payload, sender) {
147146
if (sender) {
148-
// Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
147+
Log.debug(`${this.name} received a module notification: ${notification} from sender: ${sender.name}`);
149148
} else {
150-
// Log.log(this.name + " received a system notification: " + notification);
149+
Log.debug(`${this.name} received a system notification: ${notification}`);
151150
}
152151
},
153152

js/node_helper.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ const Class = require("./class");
44

55
const NodeHelper = Class.extend({
66
init () {
7-
Log.log("Initializing new module helper ...");
7+
Log.log("[nodehelper] Initializing new module helper ...");
88
},
99

1010
loaded () {
11-
Log.log(`Module helper loaded: ${this.name}`);
11+
Log.log(`[nodehelper] Module helper loaded: ${this.name}`);
1212
},
1313

1414
start () {
15-
Log.log(`Starting module helper: ${this.name}`);
15+
Log.log(`[nodehelper] Starting module helper: ${this.name}`);
1616
},
1717

1818
/**
@@ -21,7 +21,7 @@ const NodeHelper = Class.extend({
2121
* gracefully exit the module.
2222
*/
2323
stop () {
24-
Log.log(`Stopping module helper: ${this.name}`);
24+
Log.log(`[nodehelper] Stopping module helper: ${this.name}`);
2525
},
2626

2727
/**
@@ -30,7 +30,7 @@ const NodeHelper = Class.extend({
3030
* @param {object} payload The payload of the notification.
3131
*/
3232
socketNotificationReceived (notification, payload) {
33-
Log.log(`${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
33+
Log.log(`[nodehelper] ${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
3434
},
3535

3636
/**
@@ -83,7 +83,7 @@ const NodeHelper = Class.extend({
8383
setSocketIO (io) {
8484
this.io = io;
8585

86-
Log.log(`Connecting socket for: ${this.name}`);
86+
Log.log(`[nodehelper] Connecting socket for: ${this.name}`);
8787

8888
io.of(this.name).on("connection", (socket) => {
8989
// register catch all.

js/translator.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Translator = (function () {
2020
fileInfo = JSON.parse(xhr.responseText);
2121
} catch (exception) {
2222
// nothing here, but don't die
23-
Log.error(` loading json file =${file} failed`);
23+
Log.error(`[translator] loading json file =${file} failed`);
2424
}
2525
resolve(fileInfo);
2626
}
@@ -67,22 +67,18 @@ const Translator = (function () {
6767
}
6868

6969
if (this.translations[module.name] && key in this.translations[module.name]) {
70-
// Log.log("Got translation for " + key + " from module translation: ");
7170
return createStringFromTemplate(this.translations[module.name][key], variables);
7271
}
7372

7473
if (key in this.coreTranslations) {
75-
// Log.log("Got translation for " + key + " from core translation.");
7674
return createStringFromTemplate(this.coreTranslations[key], variables);
7775
}
7876

7977
if (this.translationsFallback[module.name] && key in this.translationsFallback[module.name]) {
80-
// Log.log("Got translation for " + key + " from module translation fallback.");
8178
return createStringFromTemplate(this.translationsFallback[module.name][key], variables);
8279
}
8380

8481
if (key in this.coreTranslationsFallback) {
85-
// Log.log("Got translation for " + key + " from core translation fallback.");
8682
return createStringFromTemplate(this.coreTranslationsFallback[key], variables);
8783
}
8884

@@ -96,7 +92,7 @@ const Translator = (function () {
9692
* @param {boolean} isFallback Flag to indicate fallback translations.
9793
*/
9894
async load (module, file, isFallback) {
99-
Log.log(`${module.name} - Load translation${isFallback ? " fallback" : ""}: ${file}`);
95+
Log.log(`[translator] ${module.name} - Load translation${isFallback ? " fallback" : ""}: ${file}`);
10096

10197
if (this.translationsFallback[module.name]) {
10298
return;
@@ -113,10 +109,10 @@ const Translator = (function () {
113109
*/
114110
async loadCoreTranslations (lang) {
115111
if (lang in translations) {
116-
Log.log(`Loading core translation file: ${translations[lang]}`);
112+
Log.log(`[translator] Loading core translation file: ${translations[lang]}`);
117113
this.coreTranslations = await loadJSON(translations[lang]);
118114
} else {
119-
Log.log("Configured language not found in core translations.");
115+
Log.log("[translator] Configured language not found in core translations.");
120116
}
121117

122118
await this.loadCoreTranslationsFallback();
@@ -129,7 +125,7 @@ const Translator = (function () {
129125
async loadCoreTranslationsFallback () {
130126
let first = Object.keys(translations)[0];
131127
if (first) {
132-
Log.log(`Loading core translation fallback file: ${translations[first]}`);
128+
Log.log(`[translator] Loading core translation fallback file: ${translations[first]}`);
133129
this.coreTranslationsFallback = await loadJSON(translations[first]);
134130
}
135131
}

modules/default/alert/alert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Module.register("alert", {
124124
return new Promise((resolve) => {
125125
this.nunjucksEnvironment().render(this.getTemplate(type), data, function (err, res) {
126126
if (err) {
127-
Log.error("Failed to render alert", err);
127+
Log.error("[alert] Failed to render alert", err);
128128
}
129129

130130
resolve(res);

modules/default/calendar/calendar.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ Module.register("calendar", {
9696
Log.info(`Starting module: ${this.name}`);
9797

9898
if (this.config.colored) {
99-
Log.warn("Your are using the deprecated config values 'colored'. Please switch to 'coloredSymbol' & 'coloredText'!");
99+
Log.warn("[calendar] Your are using the deprecated config values 'colored'. Please switch to 'coloredSymbol' & 'coloredText'!");
100100
this.config.coloredText = true;
101101
this.config.coloredSymbol = true;
102102
}
103103
if (this.config.coloredSymbolOnly) {
104-
Log.warn("Your are using the deprecated config values 'coloredSymbolOnly'. Please switch to 'coloredSymbol' & 'coloredText'!");
104+
Log.warn("[calendar] Your are using the deprecated config values 'coloredSymbolOnly'. Please switch to 'coloredSymbol' & 'coloredText'!");
105105
this.config.coloredText = false;
106106
this.config.coloredSymbol = true;
107107
}
@@ -143,7 +143,7 @@ Module.register("calendar", {
143143

144144
// we check user and password here for backwards compatibility with old configs
145145
if (calendar.user && calendar.pass) {
146-
Log.warn("Deprecation warning: Please update your calendar authentication configuration.");
146+
Log.warn("[calendar] Deprecation warning: Please update your calendar authentication configuration.");
147147
Log.warn("https://docs.magicmirror.builders/modules/calendar.html#configuration-options");
148148
calendar.auth = {
149149
user: calendar.user,
@@ -160,7 +160,7 @@ Module.register("calendar", {
160160

161161
// for backward compatibility titleReplace
162162
if (typeof this.config.titleReplace !== "undefined") {
163-
Log.warn("Deprecation warning: Please consider upgrading your calendar titleReplace configuration to customEvents.");
163+
Log.warn("[calendar] Deprecation warning: Please consider upgrading your calendar titleReplace configuration to customEvents.");
164164
for (const [titlesearchstr, titlereplacestr] of Object.entries(this.config.titleReplace)) {
165165
this.config.customEvents.push({ keyword: ".*", transform: { search: titlesearchstr, replace: titlereplacestr } });
166166
}
@@ -201,7 +201,7 @@ Module.register("calendar", {
201201
// set this calendar as displayed
202202
this.calendarDisplayer[payload.url] = true;
203203
} else {
204-
Log.debug("[Calendar] DOM not updated waiting self update()");
204+
Log.debug("[calendar] DOM not updated waiting self update()");
205205
}
206206
return;
207207
}
@@ -461,10 +461,10 @@ Module.register("calendar", {
461461
if (eventStartDateMoment.isSameOrAfter(now) || (event.fullDayEvent && eventEndDateMoment.diff(now, "days") === 0)) {
462462
// Use relative time
463463
if (!this.config.hideTime && !event.fullDayEvent) {
464-
Log.debug("event not hidden and not fullday");
464+
Log.debug("[calendar] event not hidden and not fullday");
465465
timeWrapper.innerHTML = `${CalendarUtils.capFirst(eventStartDateMoment.calendar(null, { sameElse: this.config.dateFormat }))}`;
466466
} else {
467-
Log.debug("event full day or hidden");
467+
Log.debug("[calendar] event full day or hidden");
468468
timeWrapper.innerHTML = `${CalendarUtils.capFirst(
469469
eventStartDateMoment.calendar(null, {
470470
sameDay: this.config.showTimeToday ? "LT" : `[${this.translate("TODAY")}]`,
@@ -491,9 +491,9 @@ Module.register("calendar", {
491491
timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("DAYAFTERTOMORROW"));
492492
}
493493
}
494-
Log.info("event fullday");
494+
Log.info("[calendar] event fullday");
495495
} else if (eventStartDateMoment.diff(now, "h") < this.config.getRelative) {
496-
Log.info("not full day but within getrelative size");
496+
Log.info("[calendar] not full day but within getrelative size");
497497
// If event is within getRelative hours, display 'in xxx' time format or moment.fromNow()
498498
timeWrapper.innerHTML = `${CalendarUtils.capFirst(eventStartDateMoment.fromNow())}`;
499499
}
@@ -680,14 +680,14 @@ Module.register("calendar", {
680680
by_url_calevents.sort(function (a, b) {
681681
return a.startDate - b.startDate;
682682
});
683-
Log.debug(`pushing ${by_url_calevents.length} events to total with room for ${remainingEntries}`);
683+
Log.debug(`[calendar] pushing ${by_url_calevents.length} events to total with room for ${remainingEntries}`);
684684
events = events.concat(by_url_calevents.slice(0, remainingEntries));
685-
Log.debug(`events for calendar=${events.length}`);
685+
Log.debug(`[calendar] events for calendar=${events.length}`);
686686
} else {
687687
events = events.concat(by_url_calevents);
688688
}
689689
}
690-
Log.info(`sorting events count=${events.length}`);
690+
Log.info(`[calendar] sorting events count=${events.length}`);
691691
events.sort(function (a, b) {
692692
return a.startDate - b.startDate;
693693
});
@@ -721,7 +721,7 @@ Module.register("calendar", {
721721
}
722722
events = newEvents;
723723
}
724-
Log.info(`slicing events total maxcount=${this.config.maximumEntries}`);
724+
Log.info(`[calendar] slicing events total maxcount=${this.config.maximumEntries}`);
725725
return events.slice(0, this.config.maximumEntries);
726726
},
727727

@@ -936,7 +936,7 @@ Module.register("calendar", {
936936
setTimeout(
937937
() => {
938938
setInterval(() => {
939-
Log.debug("[Calendar] self update");
939+
Log.debug("[calendar] self update");
940940
if (this.config.updateOnFetch) {
941941
this.updateDom(1);
942942
} else {

0 commit comments

Comments
 (0)