@@ -91,6 +91,10 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
9191 return this . options . powersync ;
9292 }
9393
94+ get logger ( ) {
95+ return this . powersync . logger ?? console ;
96+ }
97+
9498 protected get storage ( ) {
9599 return this . options . storage ;
96100 }
@@ -123,7 +127,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
123127 async watchAttachmentIds ( ) {
124128 this . onAttachmentIdsChange ( async ( ids ) => {
125129 const _ids = `${ ids . map ( ( id ) => `'${ id } '` ) . join ( ',' ) } ` ;
126- console . debug ( `Queuing for sync, attachment IDs: [${ _ids } ]` ) ;
130+ this . logger . debug ( `Queuing for sync, attachment IDs: [${ _ids } ]` ) ;
127131
128132 if ( this . initialSync ) {
129133 this . initialSync = false ;
@@ -151,11 +155,11 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
151155 id : id ,
152156 state : AttachmentState . QUEUED_SYNC
153157 } ) ;
154- console . debug ( `Attachment (${ id } ) not found in database, creating new record` ) ;
158+ this . logger . debug ( `Attachment (${ id } ) not found in database, creating new record` ) ;
155159 await this . saveToQueue ( newRecord ) ;
156160 } else if ( record . local_uri == null || ! ( await this . storage . fileExists ( this . getLocalUri ( record . local_uri ) ) ) ) {
157161 // 2. Attachment in database but no local file, mark as queued download
158- console . debug ( `Attachment (${ id } ) found in database but no local file, marking as queued download` ) ;
162+ this . logger . debug ( `Attachment (${ id } ) found in database but no local file, marking as queued download` ) ;
159163 await this . update ( {
160164 ...record ,
161165 state : AttachmentState . QUEUED_DOWNLOAD
@@ -241,7 +245,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
241245 filename : record . filename
242246 } ) ;
243247 } catch ( e ) {
244- console . error ( e ) ;
248+ this . logger . error ( e ) ;
245249 }
246250 }
247251
@@ -267,7 +271,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
267271 const localFilePathUri = this . getLocalUri ( record . local_uri ) ;
268272 try {
269273 if ( ! ( await this . storage . fileExists ( localFilePathUri ) ) ) {
270- console . warn ( `File for ${ record . id } does not exist, skipping upload` ) ;
274+ this . logger . warn ( `File for ${ record . id } does not exist, skipping upload` ) ;
271275 await this . update ( {
272276 ...record ,
273277 state : AttachmentState . QUEUED_DOWNLOAD
@@ -285,11 +289,11 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
285289 } ) ;
286290 // Mark as uploaded
287291 await this . update ( { ...record , state : AttachmentState . SYNCED } ) ;
288- console . debug ( `Uploaded attachment "${ record . id } " to Cloud Storage` ) ;
292+ this . logger . debug ( `Uploaded attachment "${ record . id } " to Cloud Storage` ) ;
289293 return true ;
290294 } catch ( e : any ) {
291295 if ( e . error == 'Duplicate' ) {
292- console . debug ( `File already uploaded, marking ${ record . id } as synced` ) ;
296+ this . logger . debug ( `File already uploaded, marking ${ record . id } as synced` ) ;
293297 await this . update ( { ...record , state : AttachmentState . SYNCED } ) ;
294298 return false ;
295299 }
@@ -300,7 +304,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
300304 return true ;
301305 }
302306 }
303- console . error ( `UploadAttachment error for record ${ JSON . stringify ( record , null , 2 ) } ` ) ;
307+ this . logger . error ( `UploadAttachment error for record ${ JSON . stringify ( record , null , 2 ) } ` ) ;
304308 return false ;
305309 }
306310 }
@@ -314,7 +318,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
314318 }
315319 const localFilePathUri = this . getLocalUri ( record . local_uri ) ;
316320 if ( await this . storage . fileExists ( localFilePathUri ) ) {
317- console . debug ( `Local file already downloaded, marking "${ record . id } " as synced` ) ;
321+ this . logger . debug ( `Local file already downloaded, marking "${ record . id } " as synced` ) ;
318322 await this . update ( { ...record , state : AttachmentState . SYNCED } ) ;
319323 return true ;
320324 }
@@ -345,7 +349,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
345349 media_type : fileBlob . type ,
346350 state : AttachmentState . SYNCED
347351 } ) ;
348- console . debug ( `Downloaded attachment "${ record . id } "` ) ;
352+ this . logger . debug ( `Downloaded attachment "${ record . id } "` ) ;
349353 return true ;
350354 } catch ( e ) {
351355 if ( this . options . onDownloadError ) {
@@ -355,7 +359,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
355359 return true ;
356360 }
357361 }
358- console . error ( `Download attachment error for record ${ JSON . stringify ( record , null , 2 ) } ` , e ) ;
362+ this . logger . error ( `Download attachment error for record ${ JSON . stringify ( record , null , 2 ) } ` , e ) ;
359363 }
360364 return false ;
361365 }
@@ -396,7 +400,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
396400 if ( ! record ) {
397401 return ;
398402 }
399- console . debug ( `Uploading attachments...` ) ;
403+ this . logger . debug ( `Uploading attachments...` ) ;
400404 while ( record ) {
401405 const uploaded = await this . uploadAttachment ( record ) ;
402406 if ( ! uploaded ) {
@@ -405,9 +409,9 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
405409 }
406410 record = await this . getNextUploadRecord ( ) ;
407411 }
408- console . debug ( 'Finished uploading attachments' ) ;
412+ this . logger . debug ( 'Finished uploading attachments' ) ;
409413 } catch ( error ) {
410- console . error ( 'Upload failed:' , error ) ;
414+ this . logger . error ( 'Upload failed:' , error ) ;
411415 } finally {
412416 this . uploading = false ;
413417 }
@@ -464,7 +468,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
464468
465469 this . downloading = true ;
466470 try {
467- console . debug ( `Downloading ${ this . downloadQueue . size } attachments...` ) ;
471+ this . logger . debug ( `Downloading ${ this . downloadQueue . size } attachments...` ) ;
468472 while ( this . downloadQueue . size > 0 ) {
469473 const id = this . downloadQueue . values ( ) . next ( ) . value ;
470474 this . downloadQueue . delete ( id ) ;
@@ -474,9 +478,9 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
474478 }
475479 await this . downloadRecord ( record ) ;
476480 }
477- console . debug ( 'Finished downloading attachments' ) ;
481+ this . logger . debug ( 'Finished downloading attachments' ) ;
478482 } catch ( e ) {
479- console . error ( 'Downloads failed:' , e ) ;
483+ this . logger . error ( 'Downloads failed:' , e ) ;
480484 } finally {
481485 this . downloading = false ;
482486 }
@@ -518,7 +522,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
518522 return ;
519523 }
520524
521- console . debug ( `Deleting ${ res . length } attachments from cache...` ) ;
525+ this . logger . debug ( `Deleting ${ res . length } attachments from cache...` ) ;
522526 await this . powersync . writeTransaction ( async ( tx ) => {
523527 for ( const record of res ) {
524528 await this . delete ( record , tx ) ;
@@ -527,7 +531,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
527531 }
528532
529533 async clearQueue ( ) : Promise < void > {
530- console . debug ( `Clearing attachment queue...` ) ;
534+ this . logger . debug ( `Clearing attachment queue...` ) ;
531535 await this . powersync . writeTransaction ( async ( tx ) => {
532536 await tx . execute ( `DELETE FROM ${ this . table } ` ) ;
533537 } ) ;
0 commit comments