logback+slf4j整全, TimeBasedRollingPolicy不起作用
<configurationstatus="debug"scan="true"scanPeriod="1hours"><appendername="console"cla...
<configuration status="debug" scan="true" scanPeriod="1 hours">
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{36} %L %M - %msg%xEx%n</pattern>
</encoder>
</appender>
<appender name="accessfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- <file>../logs/app.log</file> -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<maxHistory>60</maxHistory>
<fileNamePattern>../logs/%d{yyyy-MM}/app-%d{MM-dd-yyyy}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %class{36} %L %M - %msg%xEx%n</pattern>
</encoder>
</appender>
<!-- 异步输出 -->
<appender name="async" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>512</queueSize>
<appender-ref ref="accessfile" />
</appender>
<root level="debug">
<appender-ref ref="console" />
<appender-ref ref="accessfile" />
</root>
<logger name="com.alibaba" level="error" addtivity="false"/>
<logger name="org.apache.http" level="error" addtivity="false"/>
<logger name="org.hibernate" level="error" addtivity="false"/>
<logger name="org.springframework" level="error" addtivity="false"/>
</configuration>
就是不会到了第二天就创建一个新的日志文件,总是用同一个文件记录日志 展开
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{36} %L %M - %msg%xEx%n</pattern>
</encoder>
</appender>
<appender name="accessfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- <file>../logs/app.log</file> -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<maxHistory>60</maxHistory>
<fileNamePattern>../logs/%d{yyyy-MM}/app-%d{MM-dd-yyyy}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %class{36} %L %M - %msg%xEx%n</pattern>
</encoder>
</appender>
<!-- 异步输出 -->
<appender name="async" class="ch.qos.logback.classic.AsyncAppender">
<discardingThreshold>0</discardingThreshold>
<queueSize>512</queueSize>
<appender-ref ref="accessfile" />
</appender>
<root level="debug">
<appender-ref ref="console" />
<appender-ref ref="accessfile" />
</root>
<logger name="com.alibaba" level="error" addtivity="false"/>
<logger name="org.apache.http" level="error" addtivity="false"/>
<logger name="org.hibernate" level="error" addtivity="false"/>
<logger name="org.springframework" level="error" addtivity="false"/>
</configuration>
就是不会到了第二天就创建一个新的日志文件,总是用同一个文件记录日志 展开
1个回答
展开全部
你应该加个trig,否则不会触发文件切换动作。
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名 -->
<FileNamePattern>${LOG_HOME}/oltp-sql.%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<!--日志文件保留天数 -->
<MaxHistory>30</MaxHistory>
<!--日志文件最大的大小 -->
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名 -->
<FileNamePattern>${LOG_HOME}/oltp-sql.%d{yyyy-MM-dd}-%i.log</FileNamePattern>
<!--日志文件保留天数 -->
<MaxHistory>30</MaxHistory>
<!--日志文件最大的大小 -->
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
追问
照你的来,报错了
Exception in Action for tag [rollingPolicy] java.lang.IndexOutOfBoundsException
:No group 1
追答
不会的,我们一直用的。你是不是一个appender里放了多个 rollingPolicy了?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询