logback 生成日誌

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

<configuration>app

<appender name="stdout"日誌

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

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

<Pattern>it

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

</Pattern>class

</layout>thread

</appender>sed

<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>

相關文章
相關標籤/搜索