日期:2014-05-18  浏览次数:20686 次

求一个log4j配置文件
求一个log4j配置文件

------解决方案--------------------
XML code
<?xml version="1.0" encoding="UTF-8"?>
<!-- SETTING FOR IN-CONTAINER TESTING -->

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <appender name="FILE" class="org.apache.log4j.FileAppender">
    <param name="File" value="c:/logs/a.log"/>
    <param name="Append" value="true"/>
    <param name="threshold" value="debug"/>
   <param name="encoding" value="GBK"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d %-5r %-5p [%c:%M:%L] (%t:%x) %m%n"/>
    </layout>
  </appender>

  <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
      <layout class="org.apache.log4j.PatternLayout">
           <param name="ConversionPattern" 
             value="%d %-5p %m (%c.java:%L)%n"/>
      </layout>
   </appender>
   
   <root>
    <priority value="info"/>
    <appender-ref ref="STDOUT"/>
  </root>
  

</log4j:configuration>

------解决方案--------------------
# Set root category priority to DEBUG and its only appender to DEFULT.

log4j.rootCategory=INFO, DEFULT

# APPENDER access

log4j.appender.access=org.apache.log4j.FileAppender

log4j.appender.access.append=true

#log4j.appender.access.append=false

 

# DEFULT uses PatternLayout.

log4j.appender.DEFULT=org.apache.log4j.RollingFileAppender

log4j.appender.DEFULT.File=C:....................................

log4j.appender.DEFULT.MaxFileSize=1MB

log4j.appender.DEFULT.MaxBackupIndex=5

log4j.appender.DEFULT.layout=org.apache.log4j.PatternLayout

log4j.appender.DEFULT.layout.ConversionPattern=*%5p [%-23d{ISO8601}] %m<%c>%n

保存文件为log4j.properties
------解决方案--------------------
og4j.rootLogger=info,CON,R

log4j.appender.CON=org.apache.log4j.ConsoleAppender
log4j.appender.CON.layout=org.apache.log4j.PatternLayout
log4j.appender.CON.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %4r %5p %c{2}:%L - %m%n


log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=mylog.log
log4j.appender.R.MaxFileSize=1024KB
log4j.appender.R.MaxBackupIndex=50

log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %4r %5p %c{2}:%L - %m%n