Skip to content

armgit / ente

Public Imported from GitHub
0

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

Support arbitrary parameters like console.log

Manav Rathi5ac4799ce112
diff --git a/desktop/src/main/init.ts b/desktop/src/main/init.ts
index da2ffddc18..df4363bace 100644
--- a/desktop/src/main/init.ts
+++ b/desktop/src/main/init.ts
@@ -161,12 +161,13 @@ export async function handleDockIconHideOnAutoLaunch() {
export function logStartupBanner() {
const version = isDev ? "dev" : app.getVersion();
- log.info(`hello from ente-photos-desktop ${version}`);
+ log.info(`Hello from ente-photos-desktop ${version}`);
- const systemVersion = process.getSystemVersion();
- const osName = process.platform;
+ const platform = process.platform;
const osRelease = os.release();
- log.info(`system info ${{ osName, osRelease, systemVersion }}`);
+ const systemVersion = process.getSystemVersion();
+ log.info("Running on", { platform, osRelease, systemVersion });
+ log.debug(() => ({ platform, osRelease, systemVersion }));
}
async function checkIfInstalledViaBrew() {
diff --git a/desktop/src/main/log.ts b/desktop/src/main/log.ts
index 2fdcccf931..8787a530d2 100644
--- a/desktop/src/main/log.ts
+++ b/desktop/src/main/log.ts
@@ -1,4 +1,5 @@
import log from "electron-log";
+import util from "node:util";
import { isDev } from "./util";
/**
@@ -72,13 +73,16 @@ const logError_ = (message: string) => {
if (isDev) console.error(`[error] ${message}`);
};
-const logInfo = (message: string) => {
+const logInfo = (...params: any[]) => {
+ const message = params
+ .map((p) => (typeof p == "string" ? p : util.inspect(p)))
+ .join(" ");
log.info(`[main] ${message}`);
if (isDev) console.log(message);
};
-const logDebug = (message: () => string) => {
- if (isDev) console.log(`[debug] ${message()}`);
+const logDebug = (param: () => any) => {
+ if (isDev) console.log(`[debug] ${util.inspect(param())}`);
};
/**
@@ -103,6 +107,9 @@ export default {
/**
* Log a message.
*
+ * This is meant as a replacement of {@link console.log}, and takes an
+ * arbitrary number of arbitrary parameters that it then serializes.
+ *
* The log is written to disk. In development builds, the log is also
* printed to the (Node.js process') console.
*/
@@ -110,12 +117,15 @@ export default {
/**
* Log a debug message.
*
- * The log is not written to disk. And it is printed to the (Node.js
- * process') console only on development builds.
- *
* To avoid running unnecessary code in release builds, this takes a
* function to call to get the log message instead of directly taking the
* message. The provided function will only be called in development builds.
+ *
+ * The function can return an arbitrary value which is serialied before
+ * being logged.
+ *
+ * This log is not written to disk. It is printed to the (Node.js process')
+ * console only on development builds.
*/
debug: logDebug,
};