Log4j 根据日期生成日志目录

公司项目分为design,runtime两个模块。design使用的logback. runtime 使用log4j.

以前系统日志都输出在console中,现在需要输出到指定目录。
log4j配置如下:
依赖:

<dependency>

<groupId>log4jgroupId>

<artifactId>apache-log4j-extrasartifactId>

<version>1.2.17version>

dependency>

log4j.xml文件配置:

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

DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration debug="true"

xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="runtime" class="org.apache.log4j.rolling.RollingFileAppender">

<param name="Append" value="true" />

<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">

<param name="FileNamePattern" value="${user.home}/symphony/%d{yyyy-MM-dd}/runtime-log.log" />  

rollingPolicy>

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d [%t] %-5p %c(%L) - %m%n" />

layout>

appender>

<appender name="message" class="org.apache.log4j.rolling.RollingFileAppender">

<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">

<param name="FileNamePattern" value="${user.home}/symphony/%d{yyyy-MM-dd}/runtime-message-log.log" />  

rollingPolicy>

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d [%t] %-5p %c(%L) - %m%n" />

layout>

appender>

<category name="com.maveriq" additivity="false">

<priority value="WARN"/>

<appender-ref ref="runtime"/>

category>

<category name="com.maveriq.communicate.core.CommunicateLog" additivity="false">

<priority value="INFO"/>

<appender-ref ref="message"/>

category>

 

    <logger name="org">  

        <level value="error" />  

    logger>  

<logger name="runtime">

        <level value="WARN">level>

<appender-ref ref="runtime" />

    logger>

<logger name="message">

<level value="INFO">level>

<appender-ref ref="message"/>

logger>

<root level="WARN">

<appender-ref ref="ERROR" />

<appender-ref ref="CONSOLE" />

<appender-ref ref="runtime" />

<appender-ref ref="message" />

root>

log4j:configuration>

你可能感兴趣的:(Java)