π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Allow disabling localStorage logs
Manav Rathiff9a28691001
diff --git a/web/apps/cast/src/pages/_app.tsx b/web/apps/cast/src/pages/_app.tsxindex 99b047d416..d85ac05422 100644--- a/web/apps/cast/src/pages/_app.tsx+++ b/web/apps/cast/src/pages/_app.tsx@@ -1,4 +1,5 @@import { CustomHead } from "@/next/components/Head";+import { disableDiskLogs } from "@/next/log";import { logUnhandledErrorsAndRejections } from "@/next/log-web";import { APPS, APP_TITLES } from "@ente/shared/apps/constants";import { getTheme } from "@ente/shared/themes";@@ -11,6 +12,7 @@ import "styles/global.css";export default function App({ Component, pageProps }: AppProps) {useEffect(() => {+ disableDiskLogs();logUnhandledErrorsAndRejections(true);return () => logUnhandledErrorsAndRejections(false);}, []);diff --git a/web/apps/cast/src/pages/index.tsx b/web/apps/cast/src/pages/index.tsxindex ac29edbf2e..192853b7ed 100644--- a/web/apps/cast/src/pages/index.tsx+++ b/web/apps/cast/src/pages/index.tsx@@ -46,7 +46,6 @@ export default function Index() {return;}- log.info("Pairing complete");storeCastData(data);await router.push("/slideshow");} catch (e) {diff --git a/web/packages/next/log.ts b/web/packages/next/log.tsindex 0129a93a16..e69d22b07e 100644--- a/web/packages/next/log.ts+++ b/web/packages/next/log.ts@@ -3,6 +3,19 @@ import { isDevBuild } from "./env";import { logToDisk as webLogToDisk } from "./log-web";import { workerBridge } from "./worker/worker-bridge";+/**+ * Whether logs go to disk or are always emitted to the console.+ */+let shouldLogToDisk = true;++/**+ * By default, logs get saved into a ring buffer in the browser's local storage.+ * However, in some contexts, e.g. when we're running as the cast app, there is+ * no mechanism for the user to retrieve these logs. So this function exists as+ * a way to disable the on disk logging and always use the console.+ */+export const disableDiskLogs = () => (shouldLogToDisk = false);+/*** Write a {@link message} to the on-disk log.*@@ -46,13 +59,13 @@ const messageWithError = (message: string, e?: unknown) => {const logError = (message: string, e?: unknown) => {const m = `[error] ${messageWithError(message, e)}`;console.error(m);- logToDisk(m);+ if (shouldLogToDisk) logToDisk(m);};const logWarn = (message: string, e?: unknown) => {const m = `[warn] ${messageWithError(message, e)}`;console.error(m);- logToDisk(m);+ if (shouldLogToDisk) logToDisk(m);};const logInfo = (...params: unknown[]) => {@@ -60,8 +73,8 @@ const logInfo = (...params: unknown[]) => {.map((p) => (typeof p == "string" ? p : JSON.stringify(p))).join(" ");const m = `[info] ${message}`;- if (isDevBuild) console.log(m);- logToDisk(m);+ if (isDevBuild || !shouldLogToDisk) console.log(m);+ if (shouldLogToDisk) logToDisk(m);};const logDebug = (param: () => unknown) => {@@ -71,8 +84,8 @@ const logDebug = (param: () => unknown) => {/*** Ente's logger.*- * This is an object that provides three functions to log at the corresponding- * levels - error, info or debug.+ * This is an object that provides functions to log at the corresponding levels:+ * error, warn, info or debug.** Whenever we need to save a log message to disk,*@@ -103,8 +116,10 @@ export default {* 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 browser console.+ * The log is written to disk. However, if logging to disk is disabled by+ * using {@link disableDiskLogs}, then the log is printed to the console.+ *+ * In development builds, the log is always printed to the browser console.*/info: logInfo,/**