mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-12-12 09:52:37 +00:00
logger: add calling filename as prefix on server side (#3926)
This commit is contained in:
@@ -132,7 +132,7 @@ function addAnimateCSS (element, animation, animationTime) {
|
||||
const node = document.getElementById(element);
|
||||
if (!node) {
|
||||
// don't execute animate: we don't find div
|
||||
Log.warn("[animateCSS] node not found for adding", element);
|
||||
Log.warn("node not found for adding", element);
|
||||
return;
|
||||
}
|
||||
node.style.setProperty("--animate-duration", `${animationTime}s`);
|
||||
@@ -149,7 +149,7 @@ function removeAnimateCSS (element, animation) {
|
||||
const node = document.getElementById(element);
|
||||
if (!node) {
|
||||
// don't execute animate: we don't find div
|
||||
Log.warn("[animateCSS] node not found for removing", element);
|
||||
Log.warn("node not found for removing", element);
|
||||
return;
|
||||
}
|
||||
node.classList.remove("animate__animated", animationName);
|
||||
|
||||
@@ -44,7 +44,7 @@ function checkConfigFile () {
|
||||
}
|
||||
|
||||
// Validate syntax of the configuration file.
|
||||
Log.info(`[checkconfig] Checking config file ${configFileName} ...`);
|
||||
Log.info(`Checking config file ${configFileName} ...`);
|
||||
|
||||
// I'm not sure if all ever is utf-8
|
||||
const configFile = fs.readFileSync(configFileName, "utf-8");
|
||||
@@ -67,7 +67,7 @@ function checkConfigFile () {
|
||||
);
|
||||
|
||||
if (errors.length === 0) {
|
||||
Log.info(styleText("green", "[checkconfig] Your configuration file doesn't contain syntax errors :)"));
|
||||
Log.info(styleText("green", "Your configuration file doesn't contain syntax errors :)"));
|
||||
validateModulePositions(configFileName);
|
||||
} else {
|
||||
let errorMessage = "Your configuration file contains syntax errors :(";
|
||||
@@ -84,7 +84,7 @@ function checkConfigFile () {
|
||||
* @param {string} configFileName - The path and filename of the configuration file to validate.
|
||||
*/
|
||||
function validateModulePositions (configFileName) {
|
||||
Log.info("[checkconfig] Checking modules structure configuration ...");
|
||||
Log.info("Checking modules structure configuration ...");
|
||||
|
||||
const positionList = Utils.getModulePositions();
|
||||
|
||||
@@ -118,7 +118,7 @@ function validateModulePositions (configFileName) {
|
||||
|
||||
const valid = validate(data);
|
||||
if (valid) {
|
||||
Log.info(styleText("green", "[checkconfig] Your modules structure configuration doesn't contain errors :)"));
|
||||
Log.info(styleText("green", "Your modules structure configuration doesn't contain errors :)"));
|
||||
} else {
|
||||
const module = validate.errors[0].instancePath.split("/")[2];
|
||||
const position = validate.errors[0].instancePath.split("/")[3];
|
||||
|
||||
@@ -40,7 +40,7 @@ function createWindow () {
|
||||
try {
|
||||
electronSize = electron.screen.getPrimaryDisplay().workAreaSize;
|
||||
} catch {
|
||||
Log.warn("[electron] Could not get display size, using defaults ...");
|
||||
Log.warn("Could not get display size, using defaults ...");
|
||||
}
|
||||
|
||||
let electronSwitchesDefaults = ["autoplay-policy", "no-user-gesture-required"];
|
||||
@@ -196,7 +196,7 @@ app.on("activate", function () {
|
||||
* core.stop() is called by process.on("SIGINT"... in `app.js`
|
||||
*/
|
||||
app.on("before-quit", async (event) => {
|
||||
Log.log("[electron] Shutting down server...");
|
||||
Log.log("Shutting down server...");
|
||||
event.preventDefault();
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
@@ -215,7 +215,7 @@ app.on("certificate-error", (event, webContents, url, error, certificate, callba
|
||||
|
||||
if (process.env.clientonly) {
|
||||
app.whenReady().then(() => {
|
||||
Log.log("[electron] Launching client viewer application.");
|
||||
Log.log("Launching client viewer application.");
|
||||
createWindow();
|
||||
});
|
||||
}
|
||||
@@ -228,7 +228,7 @@ if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].includes(co
|
||||
core.start().then((c) => {
|
||||
config = c;
|
||||
app.whenReady().then(() => {
|
||||
Log.log("[electron] Launching application.");
|
||||
Log.log("Launching application.");
|
||||
createWindow();
|
||||
});
|
||||
});
|
||||
|
||||
24
js/logger.js
24
js/logger.js
@@ -6,8 +6,30 @@
|
||||
|
||||
// add timestamps in front of log messages
|
||||
require("console-stamp")(console, {
|
||||
format: ":date(yyyy-mm-dd HH:MM:ss.l) :label(7) :msg",
|
||||
format: ":date(yyyy-mm-dd HH:MM:ss.l) :label(7) :pre() :msg",
|
||||
tokens: {
|
||||
pre: () => {
|
||||
const err = new Error();
|
||||
Error.prepareStackTrace = (_, stack) => stack;
|
||||
const stack = err.stack;
|
||||
Error.prepareStackTrace = undefined;
|
||||
try {
|
||||
for (const line of stack) {
|
||||
const file = line.getFileName();
|
||||
if (file && !file.includes("node:") && !file.includes("js/logger.js") && !file.includes("node_modules")) {
|
||||
const filename = file.replace(/.*\/(.*).js/, "$1");
|
||||
const filepath = file.replace(/.*\/(.*)\/.*.js/, "$1");
|
||||
if (filepath === "js") {
|
||||
return styleText("grey", `[${filename}]`);
|
||||
} else {
|
||||
return styleText("grey", `[${filepath}]`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
return styleText("grey", "[unknown]");
|
||||
}
|
||||
},
|
||||
label: (arg) => {
|
||||
const { method, defaultTokens } = arg;
|
||||
let label = defaultTokens.label(arg);
|
||||
|
||||
@@ -4,15 +4,15 @@ const Class = require("./class");
|
||||
|
||||
const NodeHelper = Class.extend({
|
||||
init () {
|
||||
Log.log("[nodehelper] Initializing new module helper ...");
|
||||
Log.log("Initializing new module helper ...");
|
||||
},
|
||||
|
||||
loaded () {
|
||||
Log.log(`[nodehelper] Module helper loaded: ${this.name}`);
|
||||
Log.log(`Module helper loaded: ${this.name}`);
|
||||
},
|
||||
|
||||
start () {
|
||||
Log.log(`[nodehelper] Starting module helper: ${this.name}`);
|
||||
Log.log(`Starting module helper: ${this.name}`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ const NodeHelper = Class.extend({
|
||||
* gracefully exit the module.
|
||||
*/
|
||||
stop () {
|
||||
Log.log(`[nodehelper] Stopping module helper: ${this.name}`);
|
||||
Log.log(`Stopping module helper: ${this.name}`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ const NodeHelper = Class.extend({
|
||||
* @param {object} payload The payload of the notification.
|
||||
*/
|
||||
socketNotificationReceived (notification, payload) {
|
||||
Log.log(`[nodehelper] ${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
|
||||
Log.log(`${this.name} received a socket notification: ${notification} - Payload: ${payload}`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -83,7 +83,7 @@ const NodeHelper = Class.extend({
|
||||
setSocketIO (io) {
|
||||
this.io = io;
|
||||
|
||||
Log.log(`[nodehelper] Connecting socket for: ${this.name}`);
|
||||
Log.log(`Connecting socket for: ${this.name}`);
|
||||
|
||||
io.of(this.name).on("connection", (socket) => {
|
||||
// register catch all.
|
||||
|
||||
Reference in New Issue
Block a user