Manav Rathi f10f751a2f
Inline local storage calls
The methods are trivial, and we cannot centralize the keys since they will be
different for different apps. So an abstraction for this is not beneficial.

Also move the next specific dev build check to @/next
2024-04-03 14:21:11 +05:30

40 lines
1.1 KiB
TypeScript

import { isDevBuild } from "@/next/env";
import { logError } from "@ente/shared/sentry";
import isElectron from "is-electron";
import { WorkerSafeElectronService } from "../electron/service";
import { formatLog, logWeb } from "./web";
export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
export const MAX_LOG_LINES = 1000;
export function addLogLine(
log: string | number | boolean,
...optionalParams: (string | number | boolean)[]
) {
try {
const completeLog = [log, ...optionalParams].join(" ");
if (isDevBuild) {
console.log(completeLog);
}
if (isElectron()) {
WorkerSafeElectronService.logToDisk(completeLog);
} else {
logWeb(completeLog);
}
} catch (e) {
logError(e, "failed to addLogLine", undefined, true);
// ignore
}
}
export const addLocalLog = (getLog: () => string) => {
if (isDevBuild) {
console.log(
formatLog({
logLine: getLog(),
timestamp: Date.now(),
}),
);
}
};