logback.xml配置如何按天输出日志文件

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

<appender name="stdout"

class="ch.qos.logback.core.ConsoleAppender">

<layout class="ch.qos.logback.classic.PatternLayout">

<Pattern>

%d{HH:mm:ss} [%thread] %-5level %logger{80} - %msg%n

</Pattern>

</layout>

</appender>

<appender name="R"

class="ch.qos.logback.core.rolling.RollingFileAppender">

<File>../ptvslog/server.log</File>

<layout class="ch.qos.logback.classic.PatternLayout">

<Pattern>

%d{HH:mm:ss} [%thread] %-5level %logger{80} - %msg%n

</Pattern>

</layout>

<rollingPolicy

class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">

<maxIndex>2</maxIndex>

<FileNamePattern>../ptvslog/server.log.%i</FileNamePattern>

</rollingPolicy>

<triggeringPolicy

class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">

<MaxFileSize>50MB</MaxFileSize>

</triggeringPolicy>

</appender>

(1)第一种配置如下时,将会使日志文件往后累加,而不是每日只生成当日的日志文件

<appender name="logfile"

class="ch.qos.logback.core.rolling.RollingFileAppender">

<File>../ptvslog/access.log</File>

<rollingPolicy

class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<FileNamePattern>

../ptvslog/access.%d{yyyy-MM-dd}.log

</FileNamePattern>

<!-- keep 1 days worth of history -->

<MaxHistory>1</MaxHistory>

</rollingPolicy>

<layout class="ch.qos.logback.classic.PatternLayout">

<Pattern>

%d{yyyy-MM-dd HH:mm:ss} -%msg%n

</Pattern>

</layout>

</appender>

(2)第二种配置如下时,按天生成日志文件,每天的日志文件里只保存当天的日志信息

<appender name="logfile2"

class="ch.qos.logback.core.rolling.RollingFileAppender">

<Prudent>true</Prudent>

<rollingPolicy

class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<FileNamePattern>

../ptvslog/access.%d{yyyy-MM-dd}.log

</FileNamePattern>

<!-- keep 60 days worth of history -->

<MaxHistory>60</MaxHistory>

</rollingPolicy>

<layout class="ch.qos.logback.classic.PatternLayout">

<Pattern>

%d{yyyy-MM-dd HH:mm:ss} -%msg%n

</Pattern>

</layout>

</appender>

(2)第三种配置如下时,按天生成文件夹,每个文件夹里放当天的日志文件

<appender name="logDirfile"

class="ch.qos.logback.core.rolling.RollingFileAppender">

<Prudent>true</Prudent>

<rollingPolicy

class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<FileNamePattern>

../ptvslog/%d{yyyy-MM-dd}/access.%d{yyyy-MM-dd}.log

</FileNamePattern>

</rollingPolicy>

<layout class="ch.qos.logback.classic.PatternLayout">

<Pattern>

%d{yyyy-MM-dd HH:mm:ss} -%msg%n

</Pattern>

</layout>

</appender>

以下配置表示DataController类的INFO日志以logDirfile输出,additivity="false"表示只在

logDirfile输出,不在其他输出台输出,如果设置为true,表示要在其他地方也输出。

<logger name="com.apabi.ptvs.web.DataController"

additivity="false">

<level value="INFO" />

<appender-ref ref="logDirfile" />

</logger>

<root level="INFO">

<appender-ref ref="stdout" />

<appender-ref ref="R" />

</root>

</configuration>

分类:转贴的文章 时间:2015-05-12 人气:2839
本文关键词:
分享到:

相关文章

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.051 (s). 12 q(s)