Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3396

ERROR Recursive call to appender mongodb with spring boot root logger

    XMLWordPrintableJSON

Details

    • Question
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.17.1
    • None
    • MongoDB
    • None

    Description

      If mongodb4 logger is used as root logger in basic spring boot rest application, it causes some sort of recursion error. And stalls startup. 

       below causes recursive call error

           <Root level="INFO">
            <AppenderRef ref="Console" />
            <AppenderRef ref="mongodb" />
          </Root> 
      

      while following does not produce error

        <Loggers>
          <Root level="INFO">
            <AppenderRef ref="Console" />
          </Root>
          <Logger name="com.example" level="TRACE">
            <AppenderRef ref="mongodb" >
          </Logger>
          <Logger name="io.grpc" level="INFO"/>
        </Loggers>
      

       

      2022-02-07 23:35:43,487 cluster-ClusterId{value='620182632ff6a504abdb6699', description='null'}-localhost:27017 ERROR Recursive call to appender mongodb
      23:36:13.481 [st:27017] INFO  o.m.d.cluster - Cluster description not yet available. Waiting for 30000 ms before timing out
      2022-02-07 23:36:13,480 cluster-rtt-ClusterId{value='620182632ff6a504abdb6697', description='null'}-localhost:27017 ERROR Unable to write to database [noSqlManager{ description=mongodb, bufferSize=0, provider=MongoDb4Provider [connectionString=mongodb://localhost:27017/tombolog.mongo4test, collectionSize=1073741824, isCapped=true, mongoClient=com.mongodb.client.internal.MongoClientImpl@2f67a4d3, mongoDatabase=com.mongodb.client.internal.MongoDatabaseImpl@5e3f861] }] for appender [mongodb]. org.apache.logging.log4j.core.appender.AppenderLoggingException: Failed to write log event to MongoDB due to error: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING}]
      
      

      full log4j2.xml file

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="INFO">
        <Appenders>
          <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%.8t] %-5level %logger{1.} - %msg%n"/>
          </Console>
          <NoSql name="mongodb">
            <MongoDb4 capped="true" collectionSize="1073741824" connection="${env:MONGO_LOG_URI:-mongodb://localhost:27017/log.mongo4test}" />
          </NoSql>
        </Appenders>
        <Loggers>
          <Root level="INFO">
            <AppenderRef ref="Console" />
            <AppenderRef ref="mongodb" />
          </Root>
          <Logger name="com.example" level="TRACE"/>
          <Logger name="io.grpc" level="INFO"/>
        </Loggers>
      </Configuration>
      

      build.gradle

      plugins {
      	id 'org.springframework.boot' version '2.6.3'
      	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
      	id 'java'
      }
      
      group = 'com.example'
      version = '0.0.1-SNAPSHOT'
      sourceCompatibility = '11'
      ext ['log4j2.version'] = '2.17.2-SNAPSHOT'
      
      repositories {
          mavenCentral()
          maven {
              url "http://repository.apache.org/content/repositories/snapshots/"
          }
      }
      
      dependencies {
      	implementation group: 'org.apache.logging.log4j', name: 'log4j-mongodb4', version: '2.17.2-SNAPSHOT'
      	implementation 'org.springframework.boot:spring-boot-starter-web'
      	implementation 'org.springframework.boot:spring-boot-starter-log4j2'
      	testImplementation 'org.springframework.boot:spring-boot-starter-test'
      }
      
      configurations {
      	all {
      		exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
      		exclude group: 'org.springframework.boot', module: 'logback-classic'
      	}
      }
      
      tasks.named('test') {
      	useJUnitPlatform()
      }
      
      

      is this normal behavior? I have tried to reproduce this without spring boot without any success.

      Any ideas?

      Attachments

        Activity

          People

            Unassigned Unassigned
            ugurlu Omer U
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: