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

怎么配置log4j才能让所有log不打到console上能?
现在log文件和console上都打出来了。

------解决方案--------------------
配置log4j.properties

log4j.rootCategory=debug,info,stdout(去掉), R

log4j.appender.stdout=org.apache.log4j.ConsoleAppender(全去掉)
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout(全去掉)

# Pattern to output the caller 's file name and line number.
#log4j.appender.stdout.layout.ConversionPattern=Mis2%p [%t] %C{1}.%M(%L) | %m%n
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p [%c] %m%n(全去掉)

------解决方案--------------------
log4j.rootLogger=info, stdout, file
把info改为warn以上。debug < info < warn < error < fatal
也可以把stdout去掉。

------解决方案--------------------
UP
------解决方案--------------------
你可以为package配置统一的日志记录器如:
log4j.logger.org.apache.struts=DEBUG,Console,File
也可以使用一个默认的日志记录器:
log4j.rootLogger=WARN,Console
如果log4j.logger没有配置就使用这个默认的日志记录器,但是所有配置继承此配置(在此基础增加),注意下这个就可以

------解决方案--------------------
可以解了
------解决方案--------------------
刚开始用log4j,无法回答你的问题
------解决方案--------------------
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd ">
<log4j:configuration xmlns:log4j= "http://jakarta.apache.org/log4j/ ">

<appender name= "DEBUG " class= "org.apache.log4j.RollingFileAppender ">
<param name= "File " value= "C:\\logs\\app-dbmg-debug.log "/>
<param name= "Append " value= "true "/>
<param name= "MaxFileSize " value= "10000KB "/>
<param name= "MaxBackupIndex " value= "10 "/>
<layout class= "org.apache.log4j.PatternLayout ">
<param name= "ConversionPattern " value= "%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %c %m%n "/>
</layout>
<filter class= "org.apache.log4j.varia.LevelRangeFilter ">
<param name= "LevelMin " value= "DEBUG " />
<param name= "LevelMax " value= "DEBUG " />
</filter>
</appender>

<appender name= "INFO " class= "org.apache.log4j.RollingFileAppender ">
<param name= "File " value= "C:\\logs\\app-dbmg-info.log "/>
<param name= "Append " value= "true "/>
<param name= "MaxFileSize " value= "10000KB "/>
<param name= "MaxBackupIndex " value= "10 "/>
<layout class= "org.apache.log4j.PatternLayout ">
<param name= "ConversionPattern " value= "%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %c %m%n "/>
</layout>
<filter class= "org.apache.log4j.varia.LevelRangeFilter ">
<param name= "LevelMin " value= "INFO " />
<param name= "LevelMax " value= "INFO " />
</filter>
</appender>

<appender name= "WARN " class= "org.apache.log4j.RollingFileAppender ">
<param name= "File " value= "C:\\logs\\app-dbmg-warn.log "/>
<param name= "Append " value= "true "/>