我的一個appender正在記錄到控制檯而不是文件。我有一些logback的應用程序可以很好地工作,其中一個應用程序有十多個appender。我現在正在以同樣的方式配置一個新的,但我似乎無法使其工作。Logback appender不匹配包,而是登錄到控制檯
<!-- General -->
<appender name="MAIN_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.folder}/main.log</file>
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm:ss,SSS zzz"}, level="%le", %n%caller{2}, message="%msg" %n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.folder}/main.log.%d</fileNamePattern>
</rollingPolicy>
</appender>
<logger name="com.mycompany.crawler" level="INFO" additivity="false">
<appender-ref ref="MAIN_APPENDER"/>
</logger>
<root level="INFO">
<appender-ref ref="MAIN_APPENDER"/>
</root>
<!-- Requests to Google Maps API -->
<appender name="GOOGLE_MAPS_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.folder}/maps-requests.log</file>
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm:ss,SSS zzz"}, level="%le", %n%caller{2}, message="%msg" %n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.folder}/maps-requests.log.%d</fileNamePattern>
</rollingPolicy>
</appender>
<logger name="com.google.maps" level="DEBUG" additivity="false">
<appender-ref ref="GOOGLE_MAPS_APPENDER"/>
</logger>
這是第二個GOOGLE_MAPS_APPENDER
什麼是不工作。它將記錄到控制檯而不是文件maps-requests.log
。控制檯中的消息如下所示:
Dec 06, 2016 12:53:29 PM com.google.maps.OkHttpRequestHandler handle
INFO: Request: https://maps.googleapis.com/maps/api/place/details/json?key=xxxxxxxxxx&placeid=yyyyyy&language=ar
Dec 06, 2016 12:53:31 PM com.google.maps.OkHttpRequestHandler handle
INFO: Request: https://maps.googleapis.com/maps/api/place/details/json?key=xxxxxxxxxx&placeid=yyyyyy&language=de
根據我的理解,這些行應該由appender匹配。我也試過com.google.maps.OkHttpRequestHandler
,但結果相同。我還可以確認的是,類OkHttpRequestHandler
被寫入日誌,而不是直接去安慰:
LOG.log(Level.INFO, "Request: {0}", hostName + url);
當我啓動與Maven的應用程序,它說,附加目的地正確匹配:
13:13:33,524 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
13:13:33,525 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [GOOGLE_MAPS_APPENDER]
13:13:33,525 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
13:13:33,527 |-INFO in [email protected] - No compression will be used
13:13:33,527 |-INFO in [email protected] - Will use the pattern D://code//google-maps-middleware//target/log/maps-requests.log.%d for the active file
13:13:33,528 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'D://code//google-maps-middleware//target/log/maps-requests.log.%d'.
13:13:33,528 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
13:13:33,529 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Tue Dec 06 12:44:14 CET 2016
13:13:33,530 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[GOOGLE_MAPS_APPENDER] - Active log file name: D:\\code\\google-maps-middleware\\target/log/maps-requests.log
13:13:33,530 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[GOOGLE_MAPS_APPENDER] - File property is set to [D:\\code\\google-maps-middleware\\target/log/maps-requests.log]
13:13:33,531 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.google.maps] to DEBUG
13:13:33,531 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.google.maps] to false
13:13:33,531 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [GOOGLE_MAPS_APPENDER] to Logger[com.google.maps]
13:13:33,531 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
13:13:33,533 |-INFO in [email protected] - Registering current configuration as safe fallback point
我認爲問題在於OkHttpRequestHandler
這個類在我的應用程序中是外部的,但是我在另一個應用程序中使用這個相同的模式來匹配Hibernate包並且它可以工作。我錯過了什麼?
谷歌地圖服務從JUL更改爲SLF4J [最近](https://github.com/googlemaps/google-maps-services-java/pull/186)。您可以跟進下一個版本。 – tan9