index.ts 1.1 KB

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