我想使用 Logback 将“ch.qos.logback”类记录到日志文件中,但它只记录在控制台中而不是文件中。
可能吗?
我需要它来调查 logback 的一些问题。
这是我的 logback 配置文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<configuration scan="true" scanPeriod="60 seconds">
<property name="base-path" value="../../xpto/sysX/logs"/>
<property name="application-name" value="app_X"/>
<appender class="ch.qos.logback.core.ConsoleAppender" name="CONSOLE">
<param name="Threshold" value="INFO"/>
<encoder>
<pattern>%d{dd/MM/yyyy HH:mm:ss.SSS} %-5level %logger{30} - %msg%n</pattern>
</encoder>
</appender>
<appender class="ch.qos.logback.core.rolling.RollingFileAppender" name="FILE_LOGBACK">
<param name="Threshold" value="DEBUG"/>
<file>${base-path}/mylog.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${base-path}/%d{yyyy-MM-dd_HH}/mylog.%i.log</fileNamePattern>
<maxHistory>72</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%.30thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<appender class="ch.qos.logback.classic.AsyncAppender" name="FILE_LOGBACK_ASYNC">
<param name="Threshold" value="DEBUG"/>
<appender-ref ref="FILE_LOGBACK"/>
<queueSize>1000</queueSize>
<discardingThreshold>0</discardingThreshold>
</appender>
<logger additivity="false" level="DEBUG" name="ch.qos.logback">
<appender-ref ref="FILE_LOGBACK"/>
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE_LOGBACK_ASYNC"/>
</root>
</configuration>
这是一个登录控制台的示例,我希望将它放在文件中,而不仅仅是在控制台中。
14:17:37,117 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE_LOGBACK]
14:17:37,117 |-WARN in ch.qos.logback.core.joran.util.PropertySetter@7f7f557 - No setter for property [Threshold] in ch.qos.logb ack.core.rolling.RollingFileAppender.
14:17:37,118 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@671885015 - No compression will be used
14:17:37,118 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@671885015 - Will use the pattern ../../xpto/sysX/logs/%d{ yyyy-MM-dd_HH}/mylog.%i.log for the active file
14:17:37,119 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@35ca01cb - The date pattern is 'yyyy-MM-dd_HH' from fil e name pattern '.../../xpto/sysX/logs/%d{yyyy-MM-dd_HH}/mylog.%i.log'.
14:17:37,119 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@35ca01cb - Roll-over at the top of every hour.
14:17:37,119 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@35ca01cb - Setting initial period to Mon Oct 02 14:17:3
我正在使用这个依赖项:
log4j-over-slf4j-1.7.2.jar
logback-classic-1.1.7.jar
logback-core-1.1.7.jar
slf4j-api-1.7.2.jar
提前致谢