开发luminus项目时, mongodb driver的log
2021-03-02 本文已影响0人
李富荣_Ben_Lee
console上不断的出现mongodb driver给出的logging信息, 大概每几秒钟就出现好几条:
2021-03-02 14:47:56,185 [cluster-ClusterId{value='603ddf41dbbc8d41dd3d519d', description='null'}-localhost:27017] DEBUG org.mongodb.driver.protocol.command - Execution of command with request id 13 completed successfully in 1.94 ms on connection [connectionId{localValue:1, serverValue:25}] to server localhost:27017
一开始还能忍,但当我需要自己做一些log时, 我自己的log被这些东西淹没, 我就感觉整个世界不好了。
这些信息到底从哪里来的? 研究一番,发现是clojure.tools.logging
打出来的。 查clojure.tools.logging文档,说“如果您想修改具体的配置, 就不是我的事儿了, 因为这依赖于底层实现。” WTF。
再一番周折, 终于最后搞明白了, 修改这些文件, 可以改变logging的配置:
- <my.app.project>/env/prod/resources/logback.xml
- <my.app.project>/env/dev/resources/logback.xml
- <my.app.project>/env/test/resources/logback.xml
修改方法: 添加一项:
<logger name="org.mongodb.driver.protocol.command" level="warn" />
修改后, 我的dev/resources/logback.xml为:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10 seconds">
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<charset>UTF-8</charset>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg %n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/hunxuetang.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/hunxuetang.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>
<pattern>%date{ISO8601} [%thread] %-5level %logger{36} - %msg %n</pattern>
</encoder>
</appender>
<logger name="org.apache.http" level="warn" />
<logger name="org.xnio.nio" level="warn" />
<logger name="org.mongodb.driver.cluster" level="warn" />
<logger name="org.mongodb.driver.protocol.command" level="warn" /> <!-- 这是我加的 -->
<logger name="io.undertow.websockets.core.request" level="warn" />
<logger name="io.undertow.request" level="warn" />
<logger name="io.undertow.session" level="warn" />
<logger name="io.undertow.request" level="warn" />
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>