Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Init logging

Manav Rathic38542dbfb11
diff --git a/desktop/src/main.ts b/desktop/src/main.ts
index f5bbce835e..e8c290af9e 100644
--- a/desktop/src/main.ts
+++ b/desktop/src/main.ts
@@ -14,7 +14,6 @@ import serveNextAt from "next-electron-server";
import { existsSync } from "node:fs";
import fs from "node:fs/promises";
import path from "node:path";
-import { isDev } from "./main/general";
import {
addAllowOriginHeader,
createWindow,
@@ -28,7 +27,7 @@ import {
setupTrayItem,
} from "./main/init";
import { attachFSWatchIPCHandlers, attachIPCHandlers } from "./main/ipc";
-import { logErrorSentry, setupLogging } from "./main/log";
+import { initLogging, logErrorSentry } from "./main/log";
import { initWatcher } from "./services/chokidar";
let appIsQuitting = false;
@@ -135,8 +134,6 @@ function setupAppEventEmitter(mainWindow: BrowserWindow) {
}
const main = () => {
- setupLogging(isDev);
-
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
@@ -145,6 +142,7 @@ const main = () => {
let mainWindow: BrowserWindow;
+ initLogging();
setupRendererServer();
handleDockIconHideOnAutoLaunch();
increaseDiskCache();
@@ -161,9 +159,9 @@ const main = () => {
}
});
- // This method will be called when Electron has finished
- // initialization and is ready to create browser windows.
- // Some APIs can only be used after this event occurs.
+ // Emitted once, when Electron has finished initializing.
+ //
+ // Note that some Electron APIs can only be used after this event occurs.
app.on("ready", async () => {
logSystemInfo();
mainWindow = await createWindow();
diff --git a/desktop/src/main/log.ts b/desktop/src/main/log.ts
index edffd7f34a..05f3d59c8a 100644
--- a/desktop/src/main/log.ts
+++ b/desktop/src/main/log.ts
@@ -1,15 +1,25 @@
import log from "electron-log";
import { isDev } from "./general";
-export function setupLogging(isDev?: boolean) {
+/**
+ * Initialize logging in the main process.
+ *
+ * This will set our underlying logger up to log to a file named `ente.log`,
+ *
+ * - on Linux at ~/.config/ente/logs/main.log
+ * - on macOS at ~/Library/Logs/ente/main.log
+ * - on Windows at %USERPROFILE%\AppData\Roaming\ente\logs\main.log
+ *
+ * On dev builds, it will also log to the console.
+ */
+const initLogging = () => {
log.transports.file.fileName = "ente.log";
log.transports.file.maxSize = 50 * 1024 * 1024; // 50MB;
- if (!isDev) {
- log.transports.console.level = false;
- }
log.transports.file.format =
- "[{y}-{m}-{d}T{h}:{i}:{s}{z}] [{level}]{scope} {text}";
-}
+ "[{y}-{m}-{d}T{h}:{i}:{s}{z}] [{level}] {text}";
+
+ if (!isDev) log.transports.console.level = false;
+};
export const logToDisk = (message: string) => {
log.info(message);
@@ -60,6 +70,14 @@ const logDebug = (message: () => string) => {
if (isDev) log.debug(() => message);
};
+/**
+ * Ente's logger.
+ *
+ * This is an object that provides three functions to log at the corresponding
+ * levels - error, info or debug.
+ *
+ * {@link initLogging} needs to be called once before using any of these.
+ */
export default {
/**
* Log an error message with an optional associated error object.