2023-11-02 14:30:22 +00:00
|
|
|
import isElectron from 'is-electron';
|
|
|
|
import { logError } from '@ente/shared/sentry';
|
|
|
|
import { getAppEnv } from '../apps/env';
|
|
|
|
import { APP_ENV } from '../apps/constants';
|
|
|
|
import { formatLog, logWeb } from './web';
|
2024-01-03 07:03:53 +00:00
|
|
|
import { WorkerSafeElectronService } from '../electron/service';
|
2023-11-02 14:30:22 +00:00
|
|
|
|
|
|
|
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 (getAppEnv() === APP_ENV.DEVELOPMENT) {
|
|
|
|
console.log(completeLog);
|
|
|
|
}
|
|
|
|
if (isElectron()) {
|
2024-01-03 07:03:53 +00:00
|
|
|
WorkerSafeElectronService.logToDisk(completeLog);
|
2023-11-02 14:30:22 +00:00
|
|
|
} else {
|
|
|
|
logWeb(completeLog);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
logError(e, 'failed to addLogLine', undefined, true);
|
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const addLocalLog = (getLog: () => string) => {
|
|
|
|
if (getAppEnv() === APP_ENV.DEVELOPMENT) {
|
|
|
|
console.log(
|
|
|
|
formatLog({
|
|
|
|
logLine: getLog(),
|
|
|
|
timestamp: Date.now(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|