From 41c65577a8aa0258a4a73f7ad384357cd0b5976e Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 24 Sep 2022 13:50:13 +0530 Subject: [PATCH 1/3] integrate the new electron logToDisk API --- src/services/electron/common.ts | 6 ++++++ src/types/electron/index.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/src/services/electron/common.ts b/src/services/electron/common.ts index b01c85e36..9614445c9 100644 --- a/src/services/electron/common.ts +++ b/src/services/electron/common.ts @@ -14,6 +14,12 @@ class ElectronService { checkIsBundledApp() { return isElectron() && this.isBundledApp; } + + logToDisk(msg: string) { + if (this.electronAPIs?.logToDisk) { + this.electronAPIs?.logToDisk(msg); + } + } } export default new ElectronService(); diff --git a/src/types/electron/index.ts b/src/types/electron/index.ts index 3bb4f59bc..6c52faa68 100644 --- a/src/types/electron/index.ts +++ b/src/types/electron/index.ts @@ -62,4 +62,5 @@ export interface ElectronAPIs { getEncryptionKey: () => Promise; openDiskCache: (cacheName: string) => Promise; deleteDiskCache: (cacheName: string) => Promise; + logToDisk: (msg: string) => void; } From e3730edcd4fc024135c72f7888775d583f17b564 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 24 Sep 2022 13:50:32 +0530 Subject: [PATCH 2/3] also log to disk while logging --- src/utils/logging/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/logging/index.ts b/src/utils/logging/index.ts index 55d35339d..6765e5121 100644 --- a/src/utils/logging/index.ts +++ b/src/utils/logging/index.ts @@ -3,6 +3,8 @@ import { convertBytesToHumanReadable } from 'utils/file/size'; import { formatDateTime } from 'utils/time'; import { saveLogLine, getLogs } from 'utils/storage'; import { isDEVSentryENV } from 'constants/sentry'; +import isElectron from 'is-electron'; +import ElectronService from 'services/electron/common'; export function addLogLine(log: string) { if (isDEVSentryENV()) { @@ -12,6 +14,9 @@ export function addLogLine(log: string) { timestamp: Date.now(), logLine: log, }); + if (isElectron()) { + ElectronService.logToDisk(log); + } } export const addLocalLog = (getLog: () => string) => { From 9cc3e0cf65c7623f6a4bc24fa0ba94d027819fb7 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 24 Sep 2022 16:20:24 +0530 Subject: [PATCH 3/3] improve logging --- src/components/Upload/Uploader.tsx | 2 ++ src/services/upload/uploadManager.ts | 33 ++++++++++++++-------------- src/services/upload/uploader.ts | 1 - 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/components/Upload/Uploader.tsx b/src/components/Upload/Uploader.tsx index b3190ec89..3bf574f1d 100644 --- a/src/components/Upload/Uploader.tsx +++ b/src/components/Upload/Uploader.tsx @@ -49,6 +49,7 @@ import { } from 'utils/upload'; import { getUserOwnedCollections } from 'utils/collection'; import billingService from 'services/billingService'; +import { addLogLine } from 'utils/logging'; const FIRST_ALBUM_NAME = 'My First Album'; @@ -426,6 +427,7 @@ export default function Uploader(props: Props) { const retryFailed = async () => { try { + addLogLine('user retrying failed upload'); const filesWithCollections = await uploadManager.getFailedFilesWithCollections(); await preUploadAction(); diff --git a/src/services/upload/uploadManager.ts b/src/services/upload/uploadManager.ts index f7ebaff42..dcdacbacd 100644 --- a/src/services/upload/uploadManager.ts +++ b/src/services/upload/uploadManager.ts @@ -133,8 +133,6 @@ class UploadManager { this.metadataAndFileTypeInfoMap ); - addLogLine(`clusterLivePhotoFiles called`); - // filter out files whose metadata detection failed or those that have been skipped because the files are too large, // as they will be rejected during upload and are not valid upload files which we need to clustering const rejectedFileLocalIDs = new Set( @@ -159,11 +157,16 @@ class UploadManager { } }); + addLogLine(`clusterLivePhotoFiles started`); + const analysedMediaFiles = UploadService.clusterLivePhotoFiles(filesWithMetadata); + addLogLine(`clusterLivePhotoFiles ended`); const allFiles = [...rejectedFiles, ...analysedMediaFiles]; - + addLogLine( + `got live photos: ${mediaFiles.length !== allFiles.length}` + ); uiService.setFilenames( new Map( allFiles.map((mediaFile) => [ @@ -176,9 +179,6 @@ class UploadManager { UIService.setHasLivePhoto( mediaFiles.length !== allFiles.length ); - addLogLine( - `got live photos: ${mediaFiles.length !== allFiles.length}` - ); await this.uploadMediaFiles(allFiles); } @@ -253,12 +253,12 @@ class UploadManager { } else { // and don't break for subsequent files just log and move on logError(e, 'parsing failed for a file'); + addLogLine( + `failed to parse metadata json file ${getFileNameSize( + file + )} error: ${e.message}` + ); } - addLogLine( - `failed to parse metadata json file ${getFileNameSize( - file - )} error: ${e.message}` - ); } } } catch (e) { @@ -302,12 +302,12 @@ class UploadManager { } else { // and don't break for subsequent files just log and move on logError(e, 'extractFileTypeAndMetadata failed'); + addLogLine( + `metadata extraction failed ${getFileNameSize( + file + )} error: ${e.message}` + ); } - addLogLine( - `metadata extraction failed ${getFileNameSize( - file - )} error: ${e.message}` - ); } this.metadataAndFileTypeInfoMap.set(localID, { fileTypeInfo: fileTypeInfo && { ...fileTypeInfo }, @@ -499,6 +499,7 @@ class UploadManager { } public cancelRunningUpload() { + addLogLine('user cancelled running upload'); UIService.setUploadStage(UPLOAD_STAGES.CANCELLING); uploadCancelService.requestUploadCancelation(); } diff --git a/src/services/upload/uploader.ts b/src/services/upload/uploader.ts index 40cdad7ac..895b2d603 100644 --- a/src/services/upload/uploader.ts +++ b/src/services/upload/uploader.ts @@ -131,7 +131,6 @@ export default async function uploader( backupedFile, encryptedFile.fileKey ); - addLogLine(`uploadFile ${fileNameSize}`); const uploadedFile = await UploadHttpClient.uploadFile(uploadFile);