@@ -336,7 +336,7 @@ class Consumer {
336336      else 
337337        this . #addPendingOperation( ( )  =>  this . #unassign( userAssignment ) ) ; 
338338    } ; 
339-       
339+ 
340340    try  { 
341341      err  =  LibrdKafkaError . create ( err ) ; 
342342      const  userSpecifiedRebalanceCb  =  this . #userConfig[ 'rebalance_cb' ] ; 
@@ -549,13 +549,22 @@ class Consumer {
549549    /* Creates an rdkafka config based off the kafkaJS block. Switches to compatibility mode if the block exists. */ 
550550    let  compatibleConfig  =  this . #kafkaJSToConsumerConfig( this . #userConfig. kafkaJS ) ; 
551551
552-     /* Set the logger's level in case we're not in compatibility mode - just set it to DEBUG, the broadest 
553-      * log level, as librdkafka will control the granularity. */ 
554-     if  ( ! compatibleConfig  ||  Object . keys ( compatibleConfig ) . length  ===  0 )  { 
555-       this . #logger. setLogLevel ( logLevel . DEBUG ) ; 
552+     /* There can be multiple different and conflicting config directives for setting the log level: 
553+      * 1. If there's a kafkaJS block: 
554+      *   a. If there's a logLevel directive in the kafkaJS block, set the logger level accordingly. 
555+      *   b. If there's no logLevel directive, set the logger level to INFO. 
556+      *   (both these are already handled in the conversion method above). 
557+      * 2. If there is a log_level or debug directive in the main config, set the logger level accordingly. 
558+      *    !This overrides any different value provided in the kafkaJS block! 
559+      *   a. If there's a log_level directive, set the logger level accordingly. 
560+      *   b. If there's a debug directive, set the logger level to DEBUG regardless of anything else. This is because 
561+      *      librdkafka ignores log_level if debug is set, and our behaviour should be identical. 
562+      * 3. There's nothing at all. Take no action in this case, let the logger use its default log level. 
563+      */ 
564+     if  ( Object . hasOwn ( this . #userConfig,  'log_level' ) )  { 
565+       this . #logger. setLogLevel ( severityToLogLevel [ this . #userConfig. log_level ] ) ; 
556566    } 
557567
558-     /* Even if we are in compability mode, setting a 'debug' in the main config must override the logger's level. */ 
559568    if  ( Object . hasOwn ( this . #userConfig,  'debug' ) )  { 
560569      this . #logger. setLogLevel ( logLevel . DEBUG ) ; 
561570    } 
@@ -568,8 +577,8 @@ class Consumer {
568577    /* Certain properties that the user has set are overridden. We use trampolines to accommodate the user's callbacks. 
569578     * TODO: add trampoline method for offset commit callback. */ 
570579    rdKafkaConfig [ 'offset_commit_cb' ]  =  true ; 
571-     rdKafkaConfig [ 'rebalance_cb' ]  =  ( err ,  assignment )  =>  this . #rebalanceCallback( err ,  assignment ) . catch ( e  =>   
572-       {   
580+     rdKafkaConfig [ 'rebalance_cb' ]  =  ( err ,  assignment )  =>  this . #rebalanceCallback( err ,  assignment ) . catch ( e  => 
581+       { 
573582        if  ( this . #logger) 
574583          this . #logger. error ( `Error from rebalance callback: ${ e . stack }  ` ) ; 
575584      } ) ; 
@@ -1307,7 +1316,7 @@ class Consumer {
13071316  } 
13081317
13091318  async  #checkMaxPollIntervalNotExceeded( now )  { 
1310-     const  maxPollExpiration  =  this . #lastFetchClockNs +   
1319+     const  maxPollExpiration  =  this . #lastFetchClockNs + 
13111320      BigInt ( ( this . #cacheExpirationTimeoutMs +  this . #maxPollIntervalMs) 
13121321              *  1e6 ) ; 
13131322
@@ -1317,15 +1326,15 @@ class Consumer {
13171326    await  Timer . withTimeout ( interval , 
13181327      this . #maxPollIntervalRestart) ; 
13191328    now  =  hrtime . bigint ( ) ; 
1320-      
1329+ 
13211330    if  ( now  >  ( maxPollExpiration  -  1000000n ) )  { 
13221331      this . #markBatchPayloadsStale( this . assignment ( ) ) ; 
13231332    } 
13241333  } 
13251334
13261335  /** 
13271336   * Clears the cache and resets the positions when 
1328-    * the internal client hasn't been polled for more than   
1337+    * the internal client hasn't been polled for more than 
13291338   * max poll interval since the last fetch. 
13301339   * After that it waits until barrier is reached or 
13311340   * max poll interval is reached. In the latter case it 
@@ -1334,11 +1343,11 @@ class Consumer {
13341343  async  #cacheExpirationLoop( )  { 
13351344    while  ( ! this . #workerTerminationScheduled. resolved )  { 
13361345      let  now  =  hrtime . bigint ( ) ; 
1337-       const  cacheExpiration  =  this . #lastFetchClockNs +   
1346+       const  cacheExpiration  =  this . #lastFetchClockNs + 
13381347        BigInt ( this . #cacheExpirationTimeoutMs *  1e6 ) ; 
13391348
13401349      if  ( now  >  cacheExpiration )  { 
1341-         this . #addPendingOperation( ( )  =>   
1350+         this . #addPendingOperation( ( )  => 
13421351          this . #clearCacheAndResetPositions( ) ) ; 
13431352        await  this . #checkMaxPollIntervalNotExceeded( now ) ; 
13441353        break ; 
@@ -1558,7 +1567,7 @@ class Consumer {
15581567
15591568    // Uncomment to test an additional delay in seek 
15601569    // await Timer.withTimeout(1000); 
1561-      
1570+ 
15621571    const  seekedPartitions  =  [ ] ; 
15631572    const  pendingSeeks  =  new  Map ( ) ; 
15641573    const  assignmentSet  =  new  Set ( ) ; 
@@ -1608,7 +1617,7 @@ class Consumer {
16081617    /* Offsets are committed on seek only when in compatibility mode. */ 
16091618    if  ( offsetsToCommit . length  !==  0  &&  this . #internalConfig[ 'enable.auto.commit' ] )  { 
16101619      await  this . #commitOffsetsUntilNoStateErr( offsetsToCommit ) ; 
1611-     }        
1620+     } 
16121621  } 
16131622
16141623  #markBatchPayloadsStale( topicPartitions )  { 
@@ -1828,7 +1837,7 @@ class Consumer {
18281837    } 
18291838    flattenedToppars . map ( partitionKey ) . 
18301839      forEach ( key  =>  this . #pausedPartitions. delete ( key ) ) ; 
1831-      
1840+ 
18321841    this . #addPendingOperation( ( )  => 
18331842      this . #resumeInternal( flattenedToppars ) ) ; 
18341843  } 
0 commit comments