Logback日志输出到Mongodb

Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING}]
 at com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is{type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING}]
 at         at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:370)
 at         at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)
  
 异常原因是,mongo-java-driver版本驱动没有向下兼容,换用2.7.3错误即可解决
<dependency>
 <groupId>org.mongodb</groupId>
 <artifactId>mongo-java-driver</artifactId>
 <version>2.7.3</version>
 </dependency>
 <dependency>
 <groupId>ch.qos.logback.contrib</groupId>
 <artifactId>logback-mongodb-core</artifactId>
 <version>0.1.4</version>
 </dependency>
 <dependency>
 <groupId>ch.qos.logback.contrib</groupId>
 <artifactId>logback-mongodb-classic</artifactId>
 <version>0.1.4</version>
 </dependency>
 <?xml version="1.0" encoding="UTF-8"?>
 <configuration debug="true">
  
 <property resource="common.properties" />
  
 <appender name="mongo" class="ch.qos.logback.contrib.mongodb.MongoDBLoggingEventAppender">
 <uri>${mongourl}</uri>
 <uri>mongodb://localhost:27017/scaffold.log</uri>
 <includeCallerData>true</includeCallerData>
 </appender>
  
  
 <root level="INFO">
 <appender-ref ref="mongo" />
 </root>
 <jmxConfigurator />
 </configuration>
  

参考:https://github.com/qos-ch/logback-contrib



打赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.