index.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { isDevBuild } from "@/utils/env";
  2. import { logError } from "@ente/shared/sentry";
  3. import isElectron from "is-electron";
  4. import { WorkerSafeElectronService } from "../electron/service";
  5. import { formatLog, logWeb } from "./web";
  6. export const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
  7. export const MAX_LOG_LINES = 1000;
  8. export function addLogLine(
  9. log: string | number | boolean,
  10. ...optionalParams: (string | number | boolean)[]
  11. ) {
  12. try {
  13. const completeLog = [log, ...optionalParams].join(" ");
  14. if (isDevBuild) {
  15. console.log(completeLog);
  16. }
  17. if (isElectron()) {
  18. WorkerSafeElectronService.logToDisk(completeLog);
  19. } else {
  20. logWeb(completeLog);
  21. }
  22. } catch (e) {
  23. logError(e, "failed to addLogLine", undefined, true);
  24. // ignore
  25. }
  26. }
  27. export const addLocalLog = (getLog: () => string) => {
  28. if (isDevBuild) {
  29. console.log(
  30. formatLog({
  31. logLine: getLog(),
  32. timestamp: Date.now(),
  33. }),
  34. );
  35. }
  36. };