feat: extended logging #73

This commit is contained in:
leukipp
2025-09-08 17:31:42 +02:00
parent a93fbb2ad3
commit 047b38a41b
3 changed files with 41 additions and 12 deletions
+26 -1
View File
@@ -5,6 +5,7 @@ const readline = require("readline/promises");
const integration = require("./js/integration");
const hardware = require("./js/hardware");
const webview = require("./js/webview");
const log = require("electron-log");
const { app } = require("electron");
const Events = require("events");
@@ -26,7 +27,7 @@ if (!process.env.DISPLAY) {
* initialization tasks.
*/
app.whenReady().then(async () => {
if (!(await initApp()) || !(await initArgs())) {
if (!(await initApp()) || !(await initArgs()) || !(await initLog())) {
return;
}
@@ -60,6 +61,7 @@ const initApp = async () => {
APP.version = app.getVersion();
APP.path = app.getAppPath();
APP.config = app.getPath("userData");
APP.log = path.join(app.getPath("logs"), "main.log");
// Set additional update infos
APP.homepage = `https://github.com/${packageJson.author}/${packageJson.name}`;
@@ -135,6 +137,29 @@ const initArgs = async () => {
return true;
};
/**
* Initializes the global log object.
*
* @returns {bool} Returns true if the initialization was successful.
*/
const initLog = async () => {
try {
if (fs.existsSync(APP.log)) {
fs.unlinkSync(APP.log);
}
} catch (error) {
console.error("Failed to delete log file:", error.message);
}
// Overwrite console log settings
log.transports.file.resolvePathFn = () => {
return APP.log;
};
Object.assign(console, log.functions);
return true;
};
/**
* Parses command-line arguments from the given process object.
*