diff --git a/web/apps/cast/src/utils/comlink/comlinkWorker.ts b/web/apps/cast/src/utils/comlink/comlinkWorker.ts index e924a3a96..23360a4fe 100644 --- a/web/apps/cast/src/utils/comlink/comlinkWorker.ts +++ b/web/apps/cast/src/utils/comlink/comlinkWorker.ts @@ -1,5 +1,5 @@ -import { addLocalLog } from "@ente/shared/logging"; import { Remote, wrap } from "comlink"; +import log from "@/next/log"; export class ComlinkWorker InstanceType> { public remote: Promise>>; @@ -13,13 +13,13 @@ export class ComlinkWorker InstanceType> { this.worker.onerror = (errorEvent) => { console.error("Got error event from worker", errorEvent); }; - addLocalLog(() => `Initiated ${this.name}`); + log.debug(() => `Initiated ${this.name}`); const comlink = wrap(this.worker); this.remote = new comlink() as Promise>>; } public terminate() { this.worker.terminate(); - addLocalLog(() => `Terminated ${this.name}`); + log.debug(() => `Terminated ${this.name}`); } } diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsx index 344a7722a..ffed1df8f 100644 --- a/web/apps/photos/src/components/PhotoViewer/index.tsx +++ b/web/apps/photos/src/components/PhotoViewer/index.tsx @@ -16,9 +16,9 @@ import { isSupportedRawFormat, } from "utils/file"; +import log from "@/next/log"; import { FlexWrapper } from "@ente/shared/components/Container"; import EnteSpinner from "@ente/shared/components/EnteSpinner"; -import { addLocalLog } from "@ente/shared/logging"; import AlbumOutlined from "@mui/icons-material/AlbumOutlined"; import ChevronLeft from "@mui/icons-material/ChevronLeft"; import ChevronRight from "@mui/icons-material/ChevronRight"; @@ -171,7 +171,7 @@ function PhotoViewer(props: Iprops) { return; } - addLocalLog(() => "Event: " + event.key); + log.debug(() => "Event: " + event.key); switch (event.key) { case "i": diff --git a/web/apps/photos/src/services/export/migration.ts b/web/apps/photos/src/services/export/migration.ts index 760f8f33d..6c79420ed 100644 --- a/web/apps/photos/src/services/export/migration.ts +++ b/web/apps/photos/src/services/export/migration.ts @@ -1,5 +1,4 @@ -import { addLocalLog, addLogLine } from "@ente/shared/logging"; -import { logError } from "@ente/shared/sentry"; +import log from "@/next/log"; import { LS_KEYS, getData } from "@ente/shared/storage/localStorage"; import { User } from "@ente/shared/user/types"; import { sleep } from "@ente/shared/utils"; @@ -52,25 +51,25 @@ export async function migrateExport( updateProgress: (progress: ExportProgress) => void, ) { try { - addLogLine(`current export version: ${exportRecord.version}`); + log.info(`current export version: ${exportRecord.version}`); if (exportRecord.version === 0) { - addLogLine("migrating export to version 1"); + log.info("migrating export to version 1"); await migrationV0ToV1(exportDir, exportRecord as ExportRecordV0); exportRecord = await exportService.updateExportRecord(exportDir, { version: 1, }); - addLogLine("migration to version 1 complete"); + log.info("migration to version 1 complete"); } if (exportRecord.version === 1) { - addLogLine("migrating export to version 2"); + log.info("migrating export to version 2"); await migrationV1ToV2(exportRecord as ExportRecordV1, exportDir); exportRecord = await exportService.updateExportRecord(exportDir, { version: 2, }); - addLogLine("migration to version 2 complete"); + log.info("migration to version 2 complete"); } if (exportRecord.version === 2) { - addLogLine("migrating export to version 3"); + log.info("migrating export to version 3"); await migrationV2ToV3( exportDir, exportRecord as ExportRecordV2, @@ -79,28 +78,28 @@ export async function migrateExport( exportRecord = await exportService.updateExportRecord(exportDir, { version: 3, }); - addLogLine("migration to version 3 complete"); + log.info("migration to version 3 complete"); } if (exportRecord.version === 3) { - addLogLine("migrating export to version 4"); + log.info("migrating export to version 4"); await migrationV3ToV4(exportDir, exportRecord as ExportRecord); exportRecord = await exportService.updateExportRecord(exportDir, { version: 4, }); - addLogLine("migration to version 4 complete"); + log.info("migration to version 4 complete"); } if (exportRecord.version === 4) { - addLogLine("migrating export to version 5"); + log.info("migrating export to version 5"); await migrationV4ToV5(exportDir, exportRecord as ExportRecord); exportRecord = await exportService.updateExportRecord(exportDir, { version: 5, }); - addLogLine("migration to version 5 complete"); + log.info("migration to version 5 complete"); } - addLogLine(`Record at latest version`); + log.info(`Record at latest version`); } catch (e) { - logError(e, "export record migration failed"); + log.error("export record migration failed", e); throw e; } } @@ -321,9 +320,8 @@ async function getFileExportNamesFromExportedFiles( if (!exportedFiles.length) { return; } - addLogLine( - "updating exported files to exported file paths property", - `got ${exportedFiles.length} files`, + log.info( + `updating exported files to exported file paths property, got ${exportedFiles.length} files`, ); let exportedFileNames: FileExportNames; const usedFilePaths = new Map>(); @@ -334,7 +332,7 @@ async function getFileExportNamesFromExportedFiles( for (const file of exportedFiles) { await sleep(0); const collectionPath = exportedCollectionPaths.get(file.collectionID); - addLocalLog( + log.debug( () => `collection path for ${file.collectionID} is ${collectionPath}`, ); @@ -367,7 +365,7 @@ async function getFileExportNamesFromExportedFiles( usedFilePaths, ); } - addLocalLog( + log.debug( () => `file export name for ${file.metadata.title} is ${fileExportName}`, ); @@ -419,7 +417,7 @@ async function addCollectionExportedRecordV1( await exportService.updateExportRecord(folder, exportRecord); } catch (e) { - logError(e, "addCollectionExportedRecord failed"); + log.error("addCollectionExportedRecord failed", e); throw e; } } diff --git a/web/apps/photos/src/services/upload/uploader.ts b/web/apps/photos/src/services/upload/uploader.ts index 546682924..5fb164c62 100644 --- a/web/apps/photos/src/services/upload/uploader.ts +++ b/web/apps/photos/src/services/upload/uploader.ts @@ -1,8 +1,7 @@ import { convertBytesToHumanReadable } from "@/next/file"; +import log from "@/next/log"; import { DedicatedCryptoWorker } from "@ente/shared/crypto/internal/crypto.worker"; import { CustomError, handleUploadError } from "@ente/shared/error"; -import { addLocalLog, addLogLine } from "@ente/shared/logging"; -import { logError } from "@ente/shared/sentry"; import { sleep } from "@ente/shared/utils"; import { Remote } from "comlink"; import { MAX_FILE_SIZE_SUPPORTED, UPLOAD_RESULT } from "constants/upload"; @@ -40,7 +39,7 @@ export default async function uploader( fileWithCollection, )}_${convertBytesToHumanReadable(UploadService.getAssetSize(uploadAsset))}`; - addLogLine(`uploader called for ${fileNameSize}`); + log.info(`uploader called for ${fileNameSize}`); UIService.setFileProgress(localID, 0); await sleep(0); let fileTypeInfo: FileTypeInfo; @@ -50,13 +49,13 @@ export default async function uploader( if (fileSize >= MAX_FILE_SIZE_SUPPORTED) { return { fileUploadResult: UPLOAD_RESULT.TOO_LARGE }; } - addLogLine(`getting filetype for ${fileNameSize}`); + log.info(`getting filetype for ${fileNameSize}`); fileTypeInfo = await UploadService.getAssetFileType(uploadAsset); - addLogLine( + log.info( `got filetype for ${fileNameSize} - ${JSON.stringify(fileTypeInfo)}`, ); - addLogLine(`extracting metadata ${fileNameSize}`); + log.info(`extracting metadata ${fileNameSize}`); const { metadata, publicMagicMetadata } = await UploadService.extractAssetMetadata( worker, @@ -69,7 +68,7 @@ export default async function uploader( existingFiles, metadata, ); - addLocalLog( + log.debug( () => `matchedFileList: ${matchingExistingFiles .map((f) => `${f.id}-${f.metadata.title}`) @@ -78,13 +77,13 @@ export default async function uploader( if (matchingExistingFiles?.length) { const matchingExistingFilesCollectionIDs = matchingExistingFiles.map((e) => e.collectionID); - addLocalLog( + log.debug( () => `matched file collectionIDs:${matchingExistingFilesCollectionIDs} and collectionID:${collection.id}`, ); if (matchingExistingFilesCollectionIDs.includes(collection.id)) { - addLogLine( + log.info( `file already present in the collection , skipped upload for ${fileNameSize}`, ); const sameCollectionMatchingExistingFile = @@ -96,7 +95,7 @@ export default async function uploader( uploadedFile: sameCollectionMatchingExistingFile, }; } else { - addLogLine( + log.info( `same file in ${matchingExistingFilesCollectionIDs.length} collection found for ${fileNameSize} ,adding symlink`, ); // any of the matching file can used to add a symlink @@ -112,7 +111,7 @@ export default async function uploader( if (uploadCancelService.isUploadCancelationRequested()) { throw Error(CustomError.UPLOAD_CANCELLED); } - addLogLine(`reading asset ${fileNameSize}`); + log.info(`reading asset ${fileNameSize}`); const file = await UploadService.readAsset(fileTypeInfo, uploadAsset); @@ -137,7 +136,7 @@ export default async function uploader( if (uploadCancelService.isUploadCancelationRequested()) { throw Error(CustomError.UPLOAD_CANCELLED); } - addLogLine(`encryptAsset ${fileNameSize}`); + log.info(`encryptAsset ${fileNameSize}`); const encryptedFile = await UploadService.encryptAsset( worker, fileWithMetadata, @@ -147,9 +146,9 @@ export default async function uploader( if (uploadCancelService.isUploadCancelationRequested()) { throw Error(CustomError.UPLOAD_CANCELLED); } - addLogLine(`uploadToBucket ${fileNameSize}`); + log.info(`uploadToBucket ${fileNameSize}`); const logger: Logger = (message: string) => { - addLogLine(message, `fileNameSize: ${fileNameSize}`); + log.info(message, `fileNameSize: ${fileNameSize}`); }; const backupedFile: BackupedFile = await UploadService.uploadToBucket( logger, @@ -161,11 +160,11 @@ export default async function uploader( backupedFile, encryptedFile.fileKey, ); - addLogLine(`uploading file to server ${fileNameSize}`); + log.info(`uploading file to server ${fileNameSize}`); const uploadedFile = await UploadService.uploadFile(uploadFile); - addLogLine(`${fileNameSize} successfully uploaded`); + log.info(`${fileNameSize} successfully uploaded`); return { fileUploadResult: metadata.hasStaticThumbnail @@ -174,15 +173,18 @@ export default async function uploader( uploadedFile: uploadedFile, }; } catch (e) { - addLogLine(`upload failed for ${fileNameSize} ,error: ${e.message}`); + log.info(`upload failed for ${fileNameSize} ,error: ${e.message}`); if ( e.message !== CustomError.UPLOAD_CANCELLED && e.message !== CustomError.UNSUPPORTED_FILE_FORMAT ) { - logError(e, "file upload failed", { - fileFormat: fileTypeInfo?.exactType, - fileSize: convertBytesToHumanReadable(fileSize), - }); + log.error( + `file upload failed - ${JSON.stringify({ + fileFormat: fileTypeInfo?.exactType, + fileSize: convertBytesToHumanReadable(fileSize), + })}`, + e, + ); } const error = handleUploadError(e); switch (error.message) { diff --git a/web/apps/photos/src/services/watchFolder/watchFolderService.ts b/web/apps/photos/src/services/watchFolder/watchFolderService.ts index 184ba5256..b31a3bd87 100644 --- a/web/apps/photos/src/services/watchFolder/watchFolderService.ts +++ b/web/apps/photos/src/services/watchFolder/watchFolderService.ts @@ -1,6 +1,5 @@ import ElectronAPIs from "@/next/electron"; -import { addLocalLog, addLogLine } from "@ente/shared/logging"; -import { logError } from "@ente/shared/sentry"; +import log from "@/next/log"; import { UPLOAD_RESULT, UPLOAD_STRATEGY } from "constants/upload"; import debounce from "debounce"; import uploadManager from "services/upload/uploadManager"; @@ -66,7 +65,7 @@ class watchFolderService { this.setupWatcherFunctions(); await this.getAndSyncDiffOfFiles(); } catch (e) { - logError(e, "error while initializing watch service"); + log.error("error while initializing watch service", e); } } @@ -90,7 +89,7 @@ class watchFolderService { this.trashDiffOfFiles(mapping, filesOnDisk); } } catch (e) { - logError(e, "error while getting and syncing diff of files"); + log.error("error while getting and syncing diff of files", e); } } @@ -193,7 +192,7 @@ class watchFolderService { ); this.getAndSyncDiffOfFiles(); } catch (e) { - logError(e, "error while adding watch mapping"); + log.error("error while adding watch mapping", e); } } @@ -201,7 +200,7 @@ class watchFolderService { try { await ElectronAPIs.removeWatchMapping(folderPath); } catch (e) { - logError(e, "error while removing watch mapping"); + log.error("error while removing watch mapping", e); } } @@ -209,7 +208,7 @@ class watchFolderService { try { return (await ElectronAPIs.getWatchMappings()) ?? []; } catch (e) { - logError(e, "error while getting watch mappings"); + log.error("error while getting watch mappings", e); return []; } } @@ -230,7 +229,7 @@ class watchFolderService { } const event = this.clubSameCollectionEvents(); - addLogLine( + log.info( `running event type:${event.type} collectionName:${event.collectionName} folderPath:${event.folderPath} , fileCount:${event.files?.length} pathsCount: ${event.paths?.length}`, ); const mappings = await this.getWatchMappings(); @@ -240,12 +239,12 @@ class watchFolderService { if (!mapping) { throw Error("no Mapping found for event"); } - addLogLine( + log.info( `mapping for event rootFolder: ${mapping.rootFolderName} folderPath: ${mapping.folderPath} uploadStrategy: ${mapping.uploadStrategy} syncedFilesCount: ${mapping.syncedFiles.length} ignoredFilesCount ${mapping.ignoredFiles.length}`, ); if (event.type === "upload") { event.files = getValidFilesToUpload(event.files, mapping); - addLogLine(`valid files count: ${event.files?.length}`); + log.info(`valid files count: ${event.files?.length}`); if (event.files.length === 0) { return; } @@ -262,7 +261,7 @@ class watchFolderService { setTimeout(() => this.runNextEvent(), 0); } } catch (e) { - logError(e, "runNextEvent failed"); + log.error("runNextEvent failed", e); } } @@ -273,7 +272,7 @@ class watchFolderService { this.setCollectionName(this.currentEvent.collectionName); this.setElectronFiles(this.currentEvent.files); } catch (e) { - logError(e, "error while running next upload"); + log.error("error while running next upload", e); } } @@ -282,7 +281,7 @@ class watchFolderService { fileWithCollection: FileWithCollection, file: EncryptedEnteFile, ) { - addLocalLog(() => `onFileUpload called`); + log.debug(() => `onFileUpload called`); if (!this.isUploadRunning()) { return; } @@ -338,7 +337,7 @@ class watchFolderService { collections: Collection[], ) { try { - addLocalLog( + log.debug( () => `allFileUploadsDone,${JSON.stringify( filesWithCollection, @@ -348,8 +347,8 @@ class watchFolderService { (collection) => collection.id === filesWithCollection[0].collectionID, ); - addLocalLog(() => `got collection ${!!collection}`); - addLocalLog( + log.debug(() => `got collection ${!!collection}`); + log.debug( () => `${this.isEventRunning} ${this.currentEvent.collectionName} ${collection?.name}`, ); @@ -371,8 +370,8 @@ class watchFolderService { ); } - addLocalLog(() => `syncedFiles ${JSON.stringify(syncedFiles)}`); - addLocalLog(() => `ignoredFiles ${JSON.stringify(ignoredFiles)}`); + log.debug(() => `syncedFiles ${JSON.stringify(syncedFiles)}`); + log.debug(() => `ignoredFiles ${JSON.stringify(ignoredFiles)}`); if (syncedFiles.length > 0) { this.currentlySyncedMapping.syncedFiles = [ @@ -397,7 +396,7 @@ class watchFolderService { this.runPostUploadsAction(); } catch (e) { - logError(e, "error while running all file uploads done"); + log.error("error while running all file uploads done", e); } } @@ -442,7 +441,7 @@ class watchFolderService { }; syncedFiles.push(imageFile); syncedFiles.push(videoFile); - addLocalLog( + log.debug( () => `added image ${JSON.stringify( imageFile, @@ -456,7 +455,7 @@ class watchFolderService { ) { ignoredFiles.push(imagePath); ignoredFiles.push(videoPath); - addLocalLog( + log.debug( () => `added image ${imagePath} and video file ${videoPath} to rejectedFiles`, ); @@ -476,10 +475,10 @@ class watchFolderService { .collectionID, }; syncedFiles.push(file); - addLocalLog(() => `added file ${JSON.stringify(file)} `); + log.debug(() => `added file ${JSON.stringify(file)}`); } else if (this.unUploadableFilePaths.has(filePath)) { ignoredFiles.push(filePath); - addLocalLog(() => `added file ${filePath} to rejectedFiles`); + log.debug(() => `added file ${filePath} to rejectedFiles`); } this.filePathToUploadedFileIDMap.delete(filePath); } @@ -509,7 +508,7 @@ class watchFolderService { this.currentlySyncedMapping.syncedFiles, ); } catch (e) { - logError(e, "error while running next trash"); + log.error("error while running next trash", e); } } @@ -539,7 +538,7 @@ class watchFolderService { } this.syncWithRemote(); } catch (e) { - logError(e, "error while trashing by IDs"); + log.error("error while trashing by IDs", e); } } @@ -581,7 +580,7 @@ class watchFolderService { folderPath: mapping.folderPath, }; } catch (e) { - logError(e, "error while getting collection name"); + log.error("error while getting collection name", e); } } @@ -599,7 +598,7 @@ class watchFolderService { const folderPath = await ElectronAPIs.selectDirectory(); return folderPath; } catch (e) { - logError(e, "error while selecting folder"); + log.error("error while selecting folder", e); } } @@ -627,7 +626,7 @@ class watchFolderService { const isFolder = await ElectronAPIs.isFolder(folderPath); return isFolder; } catch (e) { - logError(e, "error while checking if folder exists"); + log.error("error while checking if folder exists", e); } } diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts index 731d15f22..7558f5f29 100644 --- a/web/apps/photos/src/utils/file/index.ts +++ b/web/apps/photos/src/utils/file/index.ts @@ -1,7 +1,13 @@ -import { logError } from "@ente/shared/sentry"; +import ElectronAPIs from "@/next/electron"; +import { convertBytesToHumanReadable } from "@/next/file"; +import log from "@/next/log"; +import ComlinkCryptoWorker from "@ente/shared/crypto"; +import { CustomError } from "@ente/shared/error"; +import { isPlaybackPossible } from "@ente/shared/media/video-playback"; import { LS_KEYS, getData } from "@ente/shared/storage/localStorage"; import { User } from "@ente/shared/user/types"; import { downloadUsingAnchor } from "@ente/shared/utils"; +import { workerBridge } from "@ente/shared/worker/worker-bridge"; import { FILE_TYPE, RAW_FORMATS, @@ -11,11 +17,20 @@ import { TYPE_JPEG, TYPE_JPG, } from "constants/file"; +import { t } from "i18next"; +import isElectron from "is-electron"; +import { moveToHiddenCollection } from "services/collectionService"; import DownloadManager, { LivePhotoSourceURL, SourceURLs, } from "services/download"; import * as ffmpegService from "services/ffmpeg/ffmpegService"; +import { + deleteFromTrash, + trashFiles, + updateFileMagicMetadata, + updateFilePublicMagicMetadata, +} from "services/fileService"; import heicConversionService from "services/heicConversionService"; import { decodeLivePhoto } from "services/livePhotoService"; import { getFileType } from "services/typeDetectionService"; @@ -35,27 +50,9 @@ import { SetFilesDownloadProgressAttributesCreator, } from "types/gallery"; import { VISIBILITY_STATE } from "types/magicMetadata"; -import { isArchivedFile, updateMagicMetadata } from "utils/magicMetadata"; - -import { convertBytesToHumanReadable } from "@/next/file"; -import ComlinkCryptoWorker from "@ente/shared/crypto"; -import { CustomError } from "@ente/shared/error"; -import { addLocalLog, addLogLine } from "@ente/shared/logging"; -import { isPlaybackPossible } from "@ente/shared/media/video-playback"; -import isElectron from "is-electron"; -import { moveToHiddenCollection } from "services/collectionService"; -import { - deleteFromTrash, - trashFiles, - updateFileMagicMetadata, - updateFilePublicMagicMetadata, -} from "services/fileService"; import { FileTypeInfo } from "types/upload"; - -import ElectronAPIs from "@/next/electron"; -import { workerBridge } from "@ente/shared/worker/worker-bridge"; -import { t } from "i18next"; import { getFileExportPath, getUniqueFileExportName } from "utils/export"; +import { isArchivedFile, updateMagicMetadata } from "utils/magicMetadata"; const WAIT_TIME_IMAGE_CONVERSION = 30 * 1000; @@ -128,7 +125,7 @@ export async function downloadFile(file: EnteFile) { downloadUsingAnchor(tempURL, file.metadata.title); } } catch (e) { - logError(e, "failed to download file"); + log.error("failed to download file", e); throw e; } } @@ -244,7 +241,7 @@ export async function decryptFile( pubMagicMetadata: filePubMagicMetadata, }; } catch (e) { - logError(e, "file decryption failed"); + log.error("file decryption failed", e); throw e; } } @@ -413,19 +410,17 @@ export async function getPlayableVideo( if (!forceConvert && !runOnWeb && !isElectron()) { return null; } - addLogLine( - "video format not supported, converting it name:", - videoNameTitle, + log.info( + `video format not supported, converting it name: ${videoNameTitle}`, ); const mp4ConvertedVideo = await ffmpegService.convertToMP4( new File([videoBlob], videoNameTitle), ); - addLogLine("video successfully converted", videoNameTitle); + log.info(`video successfully converted ${videoNameTitle}`); return new Blob([await mp4ConvertedVideo.arrayBuffer()]); } } catch (e) { - addLogLine("video conversion failed", videoNameTitle); - logError(e, "video conversion failed"); + log.error("video conversion failed", e); return null; } } @@ -435,7 +430,7 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) { try { const tempFile = new File([imageBlob], fileName); fileTypeInfo = await getFileType(tempFile); - addLocalLog(() => `file type info: ${JSON.stringify(fileTypeInfo)}`); + log.debug(() => `file type info: ${JSON.stringify(fileTypeInfo)}`); const { exactType } = fileTypeInfo; let convertedImageBlob: Blob; if (isRawFile(exactType)) { @@ -447,7 +442,7 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) { if (!isElectron()) { throw Error(CustomError.NOT_AVAILABLE_ON_WEB); } - addLogLine( + log.info( `RawConverter called for ${fileName}-${convertBytesToHumanReadable( imageBlob.size, )}`, @@ -456,20 +451,20 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) { imageBlob, fileName, ); - addLogLine(`${fileName} successfully converted`); + log.info(`${fileName} successfully converted`); } catch (e) { try { if (!isFileHEIC(exactType)) { throw e; } - addLogLine( + log.info( `HEICConverter called for ${fileName}-${convertBytesToHumanReadable( imageBlob.size, )}`, ); convertedImageBlob = await heicConversionService.convert(imageBlob); - addLogLine(`${fileName} successfully converted`); + log.info(`${fileName} successfully converted`); } catch (e) { throw Error(CustomError.NON_PREVIEWABLE_FILE); } @@ -479,7 +474,10 @@ export async function getRenderableImage(fileName: string, imageBlob: Blob) { return imageBlob; } } catch (e) { - logError(e, "get Renderable Image failed", { fileTypeInfo }); + log.error( + `Failed to get renderable image for ${JSON.stringify(fileTypeInfo)}`, + e, + ); return null; } } @@ -495,7 +493,7 @@ const convertToJPEGInElectron = async ( inputFileData, filename, ); - addLogLine( + log.info( `originalFileSize:${convertBytesToHumanReadable( fileBlob?.size, )},convertedFileSize:${convertBytesToHumanReadable( @@ -508,7 +506,7 @@ const convertToJPEGInElectron = async ( e.message !== CustomError.WINDOWS_NATIVE_IMAGE_PROCESSING_NOT_SUPPORTED ) { - logError(e, "failed to convert to jpeg natively"); + log.error("failed to convert to jpeg natively", e); } throw e; } @@ -761,7 +759,7 @@ export async function downloadFiles( await downloadFile(file); progressBarUpdater?.increaseSuccess(); } catch (e) { - logError(e, "download fail for file"); + log.error("download fail for file", e); progressBarUpdater?.increaseFailed(); } } @@ -785,7 +783,7 @@ export async function downloadFilesDesktop( await downloadFileDesktop(fileReader, file, downloadPath); progressBarUpdater?.increaseSuccess(); } catch (e) { - logError(e, "download fail for file"); + log.error("download fail for file", e); progressBarUpdater?.increaseFailed(); } } @@ -890,7 +888,7 @@ export const copyFileToClipboard = async (fileUrl: string) => { clearTimeout(timeout); }; } catch (e) { - void logError(e, "failed to copy to clipboard"); + log.error("failed to copy to clipboard", e); reject(e); } finally { clearTimeout(timeout); @@ -905,7 +903,7 @@ export const copyFileToClipboard = async (fileUrl: string) => { await navigator.clipboard .write([new ClipboardItem({ "image/png": blobPromise })]) - .catch((e) => logError(e, "failed to copy to clipboard")); + .catch((e) => log.error("failed to copy to clipboard", e)); }; export function getLatestVersionFiles(files: EnteFile[]) { diff --git a/web/packages/accounts/components/Login.tsx b/web/packages/accounts/components/Login.tsx index b515cac16..e5b2ae437 100644 --- a/web/packages/accounts/components/Login.tsx +++ b/web/packages/accounts/components/Login.tsx @@ -1,3 +1,4 @@ +import log from "@/next/log"; import { APPS } from "@ente/shared/apps/constants"; import FormPaperFooter from "@ente/shared/components/Form/FormPaper/Footer"; import FormPaperTitle from "@ente/shared/components/Form/FormPaper/Title"; @@ -5,7 +6,6 @@ import LinkButton from "@ente/shared/components/LinkButton"; import SingleInputForm, { SingleInputFormProps, } from "@ente/shared/components/SingleInputForm"; -import { addLocalLog } from "@ente/shared/logging"; import { LS_KEYS, setData } from "@ente/shared/storage/localStorage"; import { Input } from "@mui/material"; import { t } from "i18next"; @@ -29,9 +29,7 @@ export default function Login(props: LoginProps) { try { setData(LS_KEYS.USER, { email }); const srpAttributes = await getSRPAttributes(email); - addLocalLog( - () => ` srpAttributes: ${JSON.stringify(srpAttributes)}`, - ); + log.debug(() => ` srpAttributes: ${JSON.stringify(srpAttributes)}`); if (!srpAttributes || srpAttributes.isEmailMFAEnabled) { await sendOtt(props.appName, email); router.push(PAGES.VERIFY); diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx index 98a78c1b4..7980eb7a5 100644 --- a/web/packages/accounts/pages/credentials.tsx +++ b/web/packages/accounts/pages/credentials.tsx @@ -1,30 +1,5 @@ -import { useEffect, useState } from "react"; - -import { t } from "i18next"; - -import { - decryptAndStoreToken, - generateAndSaveIntermediateKeyAttributes, - generateLoginSubKey, - saveKeyInSessionStore, -} from "@ente/shared/crypto/helpers"; -import { - LS_KEYS, - clearData, - getData, - setData, -} from "@ente/shared/storage/localStorage"; -import { - SESSION_KEYS, - getKey, - removeKey, - setKey, -} from "@ente/shared/storage/sessionStorage"; -import { PAGES } from "../constants/pages"; -import { generateSRPSetupAttributes } from "../services/srp"; -import { logoutUser } from "../services/user"; - import ElectronAPIs from "@/next/electron"; +import log from "@/next/log"; import { APP_HOMES } from "@ente/shared/apps/constants"; import { PageProps } from "@ente/shared/apps/types"; import { VerticallyCentered } from "@ente/shared/components/Container"; @@ -37,22 +12,47 @@ import VerifyMasterPasswordForm, { VerifyMasterPasswordFormProps, } from "@ente/shared/components/VerifyMasterPasswordForm"; import ComlinkCryptoWorker from "@ente/shared/crypto"; +import { + decryptAndStoreToken, + generateAndSaveIntermediateKeyAttributes, + generateLoginSubKey, + saveKeyInSessionStore, +} from "@ente/shared/crypto/helpers"; import { B64EncryptionResult } from "@ente/shared/crypto/types"; import { CustomError } from "@ente/shared/error"; -import { addLocalLog } from "@ente/shared/logging"; import { getAccountsURL } from "@ente/shared/network/api"; import { logError } from "@ente/shared/sentry"; import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore"; +import { + LS_KEYS, + clearData, + getData, + setData, +} from "@ente/shared/storage/localStorage"; import { getToken, isFirstLogin, setIsFirstLogin, } from "@ente/shared/storage/localStorage/helpers"; +import { + SESSION_KEYS, + getKey, + removeKey, + setKey, +} from "@ente/shared/storage/sessionStorage"; import { KeyAttributes, User } from "@ente/shared/user/types"; +import { t } from "i18next"; import isElectron from "is-electron"; import { useRouter } from "next/router"; +import { useEffect, useState } from "react"; import { getSRPAttributes } from "../api/srp"; -import { configureSRP, loginViaSRP } from "../services/srp"; +import { PAGES } from "../constants/pages"; +import { + configureSRP, + generateSRPSetupAttributes, + loginViaSRP, +} from "../services/srp"; +import { logoutUser } from "../services/user"; import { SRPAttributes } from "../types/srp"; export default function Credentials({ appContext, appName }: PageProps) { @@ -230,7 +230,7 @@ export default function Credentials({ appContext, appName }: PageProps) { setData(LS_KEYS.SRP_ATTRIBUTES, srpAttributes); } } - addLocalLog(() => `userSRPSetupPending ${!srpAttributes}`); + log.debug(() => `userSRPSetupPending ${!srpAttributes}`); if (!srpAttributes) { const loginSubKey = await generateLoginSubKey(kek); const srpSetupAttributes = diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.ts index 720080d63..e8f825a9d 100644 --- a/web/packages/accounts/services/srp.ts +++ b/web/packages/accounts/services/srp.ts @@ -1,14 +1,11 @@ -import { SRP, SrpClient } from "fast-srp-hap"; - -import { SRPAttributes, SRPSetupAttributes } from "../types/srp"; - +import log from "@/next/log"; import { UserVerificationResponse } from "@ente/accounts/types/user"; import ComlinkCryptoWorker from "@ente/shared/crypto"; import { generateLoginSubKey } from "@ente/shared/crypto/helpers"; -import { addLocalLog } from "@ente/shared/logging"; import { logError } from "@ente/shared/sentry"; import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore"; import { getToken } from "@ente/shared/storage/localStorage/helpers"; +import { SRP, SrpClient } from "fast-srp-hap"; import { v4 as uuidv4 } from "uuid"; import { completeSRPSetup, @@ -16,6 +13,7 @@ import { startSRPSetup, verifySRPSession, } from "../api/srp"; +import { SRPAttributes, SRPSetupAttributes } from "../types/srp"; import { convertBase64ToBuffer, convertBufferToBase64 } from "../utils"; const SRP_PARAMS = SRP.params["4096"]; @@ -42,7 +40,7 @@ export const configureSRP = async ({ const srpA = convertBufferToBase64(srpClient.computeA()); - addLocalLog(() => `srp a: ${srpA}`); + log.debug(() => `srp a: ${srpA}`); const token = getToken(); const { setupID, srpB } = await startSRPSetup(token, { srpA, @@ -62,7 +60,7 @@ export const configureSRP = async ({ srpClient.checkM2(convertBase64ToBuffer(srpM2)); } catch (e) { - logError(e, "srp configure failed"); + log.error("Failed to configure SRP", e); throw e; } finally { InMemoryStore.set(MS_KEYS.SRP_CONFIGURE_IN_PROGRESS, false); @@ -87,22 +85,18 @@ export const generateSRPSetupAttributes = async ( const srpVerifier = convertBufferToBase64(srpVerifierBuffer); - addLocalLog( - () => `SRP setup attributes generated', - ${JSON.stringify({ - srpSalt, - srpUserID, - srpVerifier, - loginSubKey, - })}`, - ); - - return { + const result = { srpUserID, srpSalt, srpVerifier, loginSubKey, }; + + log.debug( + () => `SRP setup attributes generated: ${JSON.stringify(result)}`, + ); + + return result; }; export const loginViaSRP = async ( @@ -124,17 +118,17 @@ export const loginViaSRP = async ( srpClient.setB(convertBase64ToBuffer(srpB)); const m1 = srpClient.computeM1(); - addLocalLog(() => `srp m1: ${convertBufferToBase64(m1)}`); + log.debug(() => `srp m1: ${convertBufferToBase64(m1)}`); const { srpM2, ...rest } = await verifySRPSession( sessionID, srpAttributes.srpUserID, convertBufferToBase64(m1), ); - addLocalLog(() => `srp verify session successful,srpM2: ${srpM2}`); + log.debug(() => `srp verify session successful,srpM2: ${srpM2}`); srpClient.checkM2(convertBase64ToBuffer(srpM2)); - addLocalLog(() => `srp server verify successful`); + log.debug(() => `srp server verify successful`); return rest; } catch (e) { logError(e, "srp verify failed"); diff --git a/web/packages/shared/logging/index.ts b/web/packages/shared/logging/index.ts index 3fd1c3fc9..a9c737412 100644 --- a/web/packages/shared/logging/index.ts +++ b/web/packages/shared/logging/index.ts @@ -1,5 +1,5 @@ import { inWorker, isDevBuild } from "@/next/env"; -import log, { logToDisk } from "@/next/log"; +import { logToDisk } from "@/next/log"; import { logError } from "@ente/shared/sentry"; import { workerBridge } from "../worker/worker-bridge"; @@ -31,5 +31,3 @@ export function addLogLine( // ignore } } - -export const addLocalLog = log.debug; diff --git a/web/packages/shared/worker/comlinkWorker.ts b/web/packages/shared/worker/comlinkWorker.ts index 0b16f142e..8432031e6 100644 --- a/web/packages/shared/worker/comlinkWorker.ts +++ b/web/packages/shared/worker/comlinkWorker.ts @@ -1,7 +1,6 @@ -import { logToDisk } from "@/next/log"; -import { addLocalLog } from "@ente/shared/logging"; -import { Remote, expose, wrap } from "comlink"; import ElectronAPIs from "@/next/electron"; +import log, { logToDisk } from "@/next/log"; +import { Remote, expose, wrap } from "comlink"; import { logError } from "../sentry"; export class ComlinkWorker InstanceType> { @@ -19,7 +18,7 @@ export class ComlinkWorker InstanceType> { name: this.name, }); }; - addLocalLog(() => `Initiated ${this.name}`); + log.debug(() => `Initiated ${this.name}`); const comlink = wrap(this.worker); this.remote = new comlink() as Promise>>; expose(workerBridge, worker); @@ -31,7 +30,7 @@ export class ComlinkWorker InstanceType> { public terminate() { this.worker.terminate(); - addLocalLog(() => `Terminated ${this.name}`); + log.debug(() => `Terminated ${this.name}`); } }