[
https://issues.apache.org/jira/browse/LOG4J2-3396?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17494916#comment-17494916
]
Ralph Goers commented on LOG4J2-3396:
-------------------------------------
I will have to look at the example but I am 100% certain the issue is that the
MongoDB client is using Log4j for logging. Those logs are then routed to the
MongoDB appender and you have an endless loop.
The fix is to provide a logger that matches what MongoDB uses and route those
message to a different destination.
> ERROR Recursive call to appender mongodb with spring boot root logger
> ---------------------------------------------------------------------
>
> Key: LOG4J2-3396
> URL: https://issues.apache.org/jira/browse/LOG4J2-3396
> Project: Log4j 2
> Issue Type: Question
> Components: MongoDB
> Affects Versions: 2.17.1
> Reporter: Omer U
> Priority: Major
>
> 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
> {code:xml}
> <Root level="INFO">
> <AppenderRef ref="Console" />
> <AppenderRef ref="mongodb" />
> </Root>
> {code}
> while following does not produce error
> {code:xml}
> <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>
> {code}
>
> {noformat}
> 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}]
> {noformat}
> full log4j2.xml file
> {code:xml}
> <?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>
> {code}
> build.gradle
> {code:groovy}
> 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()
> }
> {code}
> is this normal behavior? I have tried to reproduce this without spring boot
> without any success.
> Any ideas?
--
This message was sent by Atlassian Jira
(v8.20.1#820001)