我的一个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启动应用程序时,它表示appender正确匹配:
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 c.q.l.core.rolling.TimeBasedRollingPolicy@480870659 - No compression will be used
13:13:33,527 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@480870659 - 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 ch.qos.logback.classic.joran.JoranConfigurator@7009d85c - Registering current configuration as safe fallback point
我认为问题是类OkHttpRequestHandler
在我的应用程序外部,但我在另一个应用程序中使用相同的模式来匹配Hibernate包,它可以工作。我错过了什么?
答案 0 :(得分:0)
问题是var count = 2;
function addLine() {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var noOfCols = 4;
for (var i = 0; i < noOfCols; i++) {
var cell = row.insertCell(i);
cell.setAttribute("class", "odd");
cell.innerHTML = "<input class='whtext' name='input" + count + "d" + (i + 1) + "' type='text'>";
}
document.getElementById("counter").value = count;
count++;
}
addLine();
使用OkHttpRequestHandler
代替java.util.logging
。
解决方案只是按照in this answer所描述的方式绑定它。