feat: send logs feature that send logs to a distant service. Full integration in ui

+ expose logger method to frontEnd (#53)
This commit is contained in:
MasterAcnolo
2026-09-13 11:41:09 +02:00
parent 7dee94da6f
commit 408df0e2f6
11 changed files with 252 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ const config = require("../config");
const { validateDownloadPath, getDefaultDownloadPath } = require("./pathValidator");
const { userThemesPath } = require("../server/helpers/path.helpers");
const { createSystemTray, destroyTray } = require("./tray");
const {sendReport} = require("./sendReport");
/**
* Security whitelist for feature flags that can be modified at runtime.
@@ -180,8 +181,13 @@ function registerIpcHandlers(getMainWindow) {
*/
ipcMain.on("open-config", () => shell.openPath(configFolderPath));
/**
* Front end logger
*/
ipcMain.on("log-error", (_, message) => logger.error(`[Frontend] ${message}`));
ipcMain.on("log-info", (_, message) => logger.info(`[Frontend] ${message}`));
ipcMain.on("log-warn", (_, message) => logger.warn(`[Frontend] ${message}`));
/**
* Retrieves available themes from filesystem.
*/
@@ -199,6 +205,13 @@ function registerIpcHandlers(getMainWindow) {
return await reloadThemes();
});
/**
* Send bug report
*/
ipcMain.handle("send-report", async (_, params) => {
return await sendReport(params);
})
/**
* Updates a runtime feature flag and persists it to disk.
*

54
app/sendReport.js Normal file
View File

@@ -0,0 +1,54 @@
const fs = require("fs");
const path = require("path");
const {logger, logDir} = require("../server/logger");
async function sendReport(params) {
try {
const {title, description, includeLogs} = params;
if (!title || !description) {
throw new Error("Title and description are required.");
}
const formData = new FormData();
formData.append("title", title);
formData.append("context", description);
if (includeLogs === "yes" && logDir) {
// YYYY-MM-DD
const today = new Date().toISOString().split("T")[0];
const logFilePath = path.join(logDir, `LOGS-${today}.log`);
if (fs.existsSync(logFilePath)) {
const logFileContent = fs.readFileSync(logFilePath);
const blob = new Blob([logFileContent], {type: "text/plain"});
formData.append("file", blob, `LOGS-${today}.log`);
logger.info("Logs attached to bug report.");
} else {
logger.warn(`Log file not found for today: ${logFilePath}`);
}
}
const response = await fetch(process.env.BUG_REPORT_URL, {
method: "POST",
headers: {
"X-Api-Key": process.env.BUG_REPORT_API_KEY
},
body: formData
});
if (!response.ok) {
logger.error(`Server returned an error: ${response.status}`);
throw new Error(`Server responded with status ${response.status}`);
}
logger.info("Bug report successfully sent.");
return true;
} catch (err) {
logger.error(`Failed to send bug report: ${err.message}`);
throw err;
}
}
module.exports = {sendReport};