Skip to content

Commit bc0d365

Browse files
authored
logger: add calling filename as prefix on server side (#3926)
1 parent a1c1e95 commit bc0d365

File tree

15 files changed

+119
-97
lines changed

15 files changed

+119
-97
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +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)
32+
- [logger] Add prefixes to most Log messages (#3923, #3926)
3333

3434
## [2.33.0] - 2025-10-01
3535

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("[animateCSS] node not found for adding", element);
135+
Log.warn("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("[animateCSS] node not found for removing", element);
152+
Log.warn("node not found for removing", element);
153153
return;
154154
}
155155
node.classList.remove("animate__animated", animationName);

js/check_config.js

Lines changed: 4 additions & 4 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(`[checkconfig] Checking config file ${configFileName} ...`);
47+
Log.info(`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", "[checkconfig] Your configuration file doesn't contain syntax errors :)"));
70+
Log.info(styleText("green", "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("[checkconfig] Checking modules structure configuration ...");
87+
Log.info("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", "[checkconfig] Your modules structure configuration doesn't contain errors :)"));
121+
Log.info(styleText("green", "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];

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("[electron] Could not get display size, using defaults ...");
43+
Log.warn("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("[electron] Shutting down server...");
199+
Log.log("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("[electron] Launching client viewer application.");
218+
Log.log("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("[electron] Launching application.");
231+
Log.log("Launching application.");
232232
createWindow();
233233
});
234234
});

js/logger.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,30 @@
66

77
// add timestamps in front of log messages
88
require("console-stamp")(console, {
9-
format: ":date(yyyy-mm-dd HH:MM:ss.l) :label(7) :msg",
9+
format: ":date(yyyy-mm-dd HH:MM:ss.l) :label(7) :pre() :msg",
1010
tokens: {
11+
pre: () => {
12+
const err = new Error();
13+
Error.prepareStackTrace = (_, stack) => stack;
14+
const stack = err.stack;
15+
Error.prepareStackTrace = undefined;
16+
try {
17+
for (const line of stack) {
18+
const file = line.getFileName();
19+
if (file && !file.includes("node:") && !file.includes("js/logger.js") && !file.includes("node_modules")) {
20+
const filename = file.replace(/.*\/(.*).js/, "$1");
21+
const filepath = file.replace(/.*\/(.*)\/.*.js/, "$1");
22+
if (filepath === "js") {
23+
return styleText("grey", `[${filename}]`);
24+
} else {
25+
return styleText("grey", `[${filepath}]`);
26+
}
27+
}
28+
}
29+
} catch (err) {
30+
return styleText("grey", "[unknown]");
31+
}
32+
},
1133
label: (arg) => {
1234
const { method, defaultTokens } = arg;
1335
let label = defaultTokens.label(arg);

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("[nodehelper] Initializing new module helper ...");
7+
Log.log("Initializing new module helper ...");
88
},
99

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

1414
start () {
15-
Log.log(`[nodehelper] Starting module helper: ${this.name}`);
15+
Log.log(`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(`[nodehelper] Stopping module helper: ${this.name}`);
24+
Log.log(`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(`[nodehelper] ${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
33+
Log.log(`${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(`[nodehelper] Connecting socket for: ${this.name}`);
86+
Log.log(`Connecting socket for: ${this.name}`);
8787

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

modules/default/calendar/calendarfetcher.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
5757

5858
try {
5959
data = ical.parseICS(responseData);
60-
Log.debug(`[calendar] parsed data=${JSON.stringify(data, null, 2)}`);
60+
Log.debug(`parsed data=${JSON.stringify(data, null, 2)}`);
6161
events = CalendarFetcherUtils.filterEvents(data, {
6262
excludedEvents,
6363
includePastEvents,
@@ -91,7 +91,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn
9191
* Broadcast the existing events.
9292
*/
9393
this.broadcastEvents = function () {
94-
Log.info(`[calendar] Fetcher: Broadcasting ${events.length} events from ${url}.`);
94+
Log.info(`Fetcher: Broadcasting ${events.length} events from ${url}.`);
9595
eventsReceivedCallback(this);
9696
};
9797

modules/default/calendar/calendarfetcherutils.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,26 @@ const CalendarFetcherUtils = {
9595
const oneDayInMs = 24 * 60 * 60000;
9696
let searchFromDate = pastLocalMoment.clone().subtract(Math.max(durationInMs, oneDayInMs), "milliseconds").toDate();
9797
let searchToDate = futureLocalMoment.clone().add(1, "days").toDate();
98-
Log.debug(`[calendar] Search for recurring events between: ${searchFromDate} and ${searchToDate}`);
98+
Log.debug(`Search for recurring events between: ${searchFromDate} and ${searchToDate}`);
9999

100100
// if until is set, and its a full day event, force the time to midnight. rrule gets confused with non-00 offset
101101
// looks like MS Outlook sets the until time incorrectly for fullday events
102102
if ((rule.options.until !== undefined) && CalendarFetcherUtils.isFullDayEvent(event)) {
103-
Log.debug("[calendar] fixup rrule until");
103+
Log.debug("fixup rrule until");
104104
rule.options.until = moment(rule.options.until).clone().startOf("day").add(1, "day")
105105
.toDate();
106106
}
107107

108-
Log.debug("[calendar] fix rrule start=", rule.options.dtstart);
109-
Log.debug("[calendar] event before rrule.between=", JSON.stringify(event, null, 2), "exdates=", event.exdate);
110-
Log.debug(`[calendar] RRule: ${rule.toString()}`);
108+
Log.debug("fix rrule start=", rule.options.dtstart);
109+
Log.debug("event before rrule.between=", JSON.stringify(event, null, 2), "exdates=", event.exdate);
110+
Log.debug(`RRule: ${rule.toString()}`);
111111
rule.options.tzid = null; // RRule gets *very* confused with timezones
112112

113113
let dates = rule.between(searchFromDate, searchToDate, true, () => {
114114
return true;
115115
});
116116

117-
Log.debug(`[calendar] Title: ${event.summary}, with dates: \n\n${JSON.stringify(dates)}\n`);
117+
Log.debug(`Title: ${event.summary}, with dates: \n\n${JSON.stringify(dates)}\n`);
118118

119119
// shouldn't need this anymore, as RRULE not passed junk
120120
dates = dates.filter((d) => {
@@ -140,7 +140,7 @@ const CalendarFetcherUtils = {
140140
return CalendarFetcherUtils.isFullDayEvent(event) ? startMoment.startOf("day") : startMoment;
141141
};
142142

143-
Log.debug(`[calendar] There are ${Object.entries(data).length} calendar entries.`);
143+
Log.debug(`There are ${Object.entries(data).length} calendar entries.`);
144144

145145
const now = moment();
146146
const pastLocalMoment = config.includePastEvents ? now.clone().startOf("day").subtract(config.maximumNumberOfDays, "days") : now;
@@ -153,10 +153,10 @@ const CalendarFetcherUtils = {
153153
.subtract(1, "seconds");
154154

155155
Object.entries(data).forEach(([key, event]) => {
156-
Log.debug("[calendar] Processing entry...");
156+
Log.debug("Processing entry...");
157157

158158
const title = CalendarFetcherUtils.getTitleFromEvent(event);
159-
Log.debug(`[calendar] title: ${title}`);
159+
Log.debug(`title: ${title}`);
160160

161161
// Return quickly if event should be excluded.
162162
let { excluded, eventFilterUntil } = this.shouldEventBeExcluded(config, title);
@@ -174,7 +174,7 @@ const CalendarFetcherUtils = {
174174
}
175175

176176
if (event.type === "VEVENT") {
177-
Log.debug(`[calendar] Event:\n${JSON.stringify(event, null, 2)}`);
177+
Log.debug(`Event:\n${JSON.stringify(event, null, 2)}`);
178178
let eventStartMoment = eventDate(event, "start");
179179
let eventEndMoment;
180180

@@ -191,12 +191,12 @@ const CalendarFetcherUtils = {
191191
}
192192
}
193193

194-
Log.debug(`[calendar] start: ${eventStartMoment.toDate()}`);
195-
Log.debug(`[calendar] end: ${eventEndMoment.toDate()}`);
194+
Log.debug(`start: ${eventStartMoment.toDate()}`);
195+
Log.debug(`end: ${eventEndMoment.toDate()}`);
196196

197197
// Calculate the duration of the event for use with recurring events.
198198
const durationMs = eventEndMoment.valueOf() - eventStartMoment.valueOf();
199-
Log.debug(`[calendar] duration: ${durationMs}`);
199+
Log.debug(`duration: ${durationMs}`);
200200

201201
const location = event.location || false;
202202
const geo = event.geo || false;
@@ -217,12 +217,12 @@ const CalendarFetcherUtils = {
217217

218218
let dateKey = recurringEventStartMoment.tz("UTC").format("YYYY-MM-DD");
219219

220-
Log.debug("[calendar] event date dateKey=", dateKey);
220+
Log.debug("event date dateKey=", dateKey);
221221
// For each date that we're checking, it's possible that there is a recurrence override for that one day.
222222
if (curEvent.recurrences !== undefined) {
223-
Log.debug("[calendar] have recurrences=", curEvent.recurrences);
223+
Log.debug("have recurrences=", curEvent.recurrences);
224224
if (curEvent.recurrences[dateKey] !== undefined) {
225-
Log.debug("[calendar] have a recurrence match for dateKey=", dateKey);
225+
Log.debug("have a recurrence match for dateKey=", dateKey);
226226
// We found an override, so for this recurrence, use a potentially different title, start date, and duration.
227227
curEvent = curEvent.recurrences[dateKey];
228228
// Some event start/end dates don't have timezones
@@ -237,12 +237,12 @@ const CalendarFetcherUtils = {
237237
recurringEventEndMoment = moment(curEvent.end).tz(CalendarFetcherUtils.getLocalTimezone());
238238
}
239239
} else {
240-
Log.debug("[calendar] recurrence key ", dateKey, " doesn't match");
240+
Log.debug("recurrence key ", dateKey, " doesn't match");
241241
}
242242
}
243243
// If there's no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
244244
if (curEvent.exdate !== undefined) {
245-
Log.debug("[calendar] have datekey=", dateKey, " exdates=", curEvent.exdate);
245+
Log.debug("have datekey=", dateKey, " exdates=", curEvent.exdate);
246246
if (curEvent.exdate[dateKey] !== undefined) {
247247
// This date is an exception date, which means we should skip it in the recurrence pattern.
248248
showRecurrence = false;
@@ -266,7 +266,7 @@ const CalendarFetcherUtils = {
266266
}
267267

268268
if (showRecurrence === true) {
269-
Log.debug(`[calendar] saving event: ${recurrenceTitle}`);
269+
Log.debug(`saving event: ${recurrenceTitle}`);
270270
newEvents.push({
271271
title: recurrenceTitle,
272272
startDate: recurringEventStartMoment.format("x"),
@@ -280,7 +280,7 @@ const CalendarFetcherUtils = {
280280
description: description
281281
});
282282
} else {
283-
Log.debug("[calendar] not saving event ", recurrenceTitle, eventStartMoment);
283+
Log.debug("not saving event ", recurrenceTitle, eventStartMoment);
284284
}
285285
}
286286
// End recurring event parsing.

modules/default/calendar/debug.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ const auth = {
2121
pass: pass
2222
};
2323

24-
Log.log("[calendar] Create fetcher ...");
24+
Log.log("Create fetcher ...");
2525

2626
const fetcher = new CalendarFetcher(url, fetchInterval, [], maximumEntries, maximumNumberOfDays, auth);
2727

2828
fetcher.onReceive(function (fetcher) {
29-
Log.log("[calendar] ", fetcher.events());
29+
Log.log(fetcher.events());
3030
process.exit(0);
3131
});
3232

3333
fetcher.onError(function (fetcher, error) {
34-
Log.log("[calendar] Fetcher error:", error);
34+
Log.log("Fetcher error:", error);
3535
process.exit(1);
3636
});
3737

3838
fetcher.startFetch();
3939

40-
Log.log("[calendar] Create fetcher done! ");
40+
Log.log("Create fetcher done! ");

0 commit comments

Comments
 (0)