@@ -745,23 +745,25 @@ class Worker<TCatalog extends WorkerCatalog> {
745745 ) . catch ( async ( error ) => {
746746 const errorMessage = error instanceof Error ? error . message : String ( error ) ;
747747 const shouldLogError = catalogItem . logErrors ?? true ;
748+ const errorLogLevel =
749+ error && typeof error === "object" && "logLevel" in error ? error . logLevel : undefined ;
748750
749- if ( shouldLogError ) {
750- this . logger . error ( `Worker error processing batch` , {
751- name : this . options . name ,
752- jobType,
753- batchSize : items . length ,
754- error,
755- errorMessage,
756- } ) ;
751+ const logAttributes = {
752+ name : this . options . name ,
753+ jobType,
754+ batchSize : items . length ,
755+ error,
756+ errorMessage,
757+ } ;
758+
759+ if ( ! shouldLogError ) {
760+ this . logger . info ( `Worker failed to process batch` , logAttributes ) ;
761+ } else if ( errorLogLevel === "warn" ) {
762+ this . logger . warn ( `Worker error processing batch` , logAttributes ) ;
763+ } else if ( errorLogLevel === "info" ) {
764+ this . logger . info ( `Worker error processing batch` , logAttributes ) ;
757765 } else {
758- this . logger . info ( `Worker failed to process batch` , {
759- name : this . options . name ,
760- jobType,
761- batchSize : items . length ,
762- error,
763- errorMessage,
764- } ) ;
766+ this . logger . error ( `Worker error processing batch` , logAttributes ) ;
765767 }
766768
767769 // Re-enqueue each item individually with retry logic
@@ -775,20 +777,21 @@ class Worker<TCatalog extends WorkerCatalog> {
775777 const retryDelay = calculateNextRetryDelay ( retrySettings , newAttempt ) ;
776778
777779 if ( ! retryDelay ) {
778- if ( shouldLogError ) {
779- this . logger . error ( `Worker batch item reached max attempts. Moving to DLQ.` , {
780- name : this . options . name ,
781- id : item . id ,
782- jobType,
783- attempt : newAttempt ,
784- } ) ;
780+ const dlqLogAttributes = {
781+ name : this . options . name ,
782+ id : item . id ,
783+ jobType,
784+ attempt : newAttempt ,
785+ } ;
786+
787+ if ( ! shouldLogError ) {
788+ this . logger . info ( `Worker batch item reached max attempts. Moving to DLQ.` , dlqLogAttributes ) ;
789+ } else if ( errorLogLevel === "warn" ) {
790+ this . logger . warn ( `Worker batch item reached max attempts. Moving to DLQ.` , dlqLogAttributes ) ;
791+ } else if ( errorLogLevel === "info" ) {
792+ this . logger . info ( `Worker batch item reached max attempts. Moving to DLQ.` , dlqLogAttributes ) ;
785793 } else {
786- this . logger . info ( `Worker batch item reached max attempts. Moving to DLQ.` , {
787- name : this . options . name ,
788- id : item . id ,
789- jobType,
790- attempt : newAttempt ,
791- } ) ;
794+ this . logger . error ( `Worker batch item reached max attempts. Moving to DLQ.` , dlqLogAttributes ) ;
792795 }
793796
794797 await this . queue . moveToDeadLetterQueue ( item . id , errorMessage ) ;
0 commit comments