当前位置: 代码迷 >> J2SE >> log4j 有关问题
  详细解决方案

log4j 有关问题

热度:19   发布时间:2016-04-24 16:29:16.0
log4j 问题
我在一个main方法测试log4j
package   log4j;
import   org.apache.log4j.*;
public   class   TestLog   {
static   Logger   logger   =   Logger.getLogger(TestLog.class);//First   step

/**
  *   @param   args
  */
public   static   void   main(String[]   args)   {
//   TODO   Auto-generated   method   stub
            PropertyConfigurator.configure( "log4j.properties ");//Second   step
            logger.debug( "Here   is   some   DEBUG ");//Third   step
            logger.info( "Here   is   some   INFO ");
            logger.warn( "Here   is   some   WARN ");
            logger.error( "Here   is   some   ERROR ");
            logger.fatal( "Here   is   some   FATAL ");

}

}
控制台老是输出
[main]   INFO   log4j.TestLog   -   Here   is   some   INFO
[main]   WARN   log4j.TestLog   -   Here   is   some   WARN
[main]   ERROR   log4j.TestLog   -   Here   is   some   ERROR
[main]   FATAL   log4j.TestLog   -   Here   is   some   FATAL
log4j:WARN   No   such   property   [conversionPattern]   in   org.apache.log4j.TTCCLayout.
log4j:ERROR   Could   not   read   configuration   file   [log4j.properties].
java.io.FileNotFoundException:   log4j.properties   (系统找不到指定的文件。)
怎么找不到啊。
我那个log4j.properties都放了3个web_inf     class   lib都放力量


------解决方案--------------------
PropertyConfigurator.configure( "log4j.properties ");//Second step
这么写你应该把它放在工程目录底下的;如果放在src底下,可以把这句省略的吧

org.apache.log4j.TTCCLayout 为什么找不到我也不知道,包不全么?
另外,“控制台老是输出”log4j可能也在控制台输出的呀

控制台+文件:

log4j.rootLogger=warn, console, file

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %-5p %-5c{3}:%L %x -> %m%n

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log/importResult.txt
log4j.appender.file.layout=org.apache.log4j.PatternLayout

控制台+文件:
log4j.rootLogger=warn, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log/importResult.txt
log4j.appender.file.layout=org.apache.log4j.PatternLayout


------解决方案--------------------
学习