我正在使用log4j版本1.2.15,在执行代码时我能够获取日志文件和.html但是在控制台中它会生成以下错误:
log4j:ERROR Could not find value for key log4j.appender.CONSOLE
log4j:ERROR Could not instantiate appender named "CONSOLE".
我正在使用以下属性文件:
log4j.rootLogger= INFO,CONSOLE,R,HTML,TTCC
//Here we define the appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.TTCC=org.apache.log4j.RollingFileAppender
log4j.appender.HTML=org.apache.log4j.FileAppender
// Here we define log file location
log4j.appender.R.File=./log/testlog.log
log4j.appender.TTCC.File=./log/testlog.log
log4j.appender.HTML.File=./log/aplication.html
// Here we define the layout and pattern
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern= [%t:%p] %c: %m%n
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern= %d - %c -%p -%m%n
log4j.appender.TTCC.layout=org.apache.log4j.TTCCLayout
log4j.appender.TTCC.layout.DateFormat=ISO8601
log4j.appender.HTML.layout=org.apache.log4j.HTMLLayout
log4j.appender.HTML.layout.Title=Application log
log4j.appender.HTML.layout.LocationInfo= true
另外,我不会在日志文件中理解为什么它会使用" main "两次打印相同的行。和" 演示",请查看以下内容:
015-08-10 21:25:08,921 - demo -INFO -New driver instantiated
2015-08-10 21:25:08,921 [main] INFO demo - New driver instantiated
2015-08-10 21:25:09,000 - demo -INFO -Implicit wait applied on the driver for 10 seconds
2015-08-10 21:25:09,000 [main] INFO demo - Implicit wait applied on the driver for 10 seconds
2015-08-10 21:25:42,156 - demo -INFO -Web application launched
2015-08-10 21:25:42,156 [main] INFO demo - Web application launched
任何人都可以让我知道确切的问题是什么? 另外,我是第一次看到教程。所以,请帮助我。
答案 0 :(得分:1)
您的根记录器定义显示CONSOLE
(全部大写)。但你是在发起
log4j.appender
console
(较小的情况)。
根据log4j documentation
记录器名称区分大小写
更改行
log4j.rootLogger= INFO,CONSOLE,R,HTML,TTCC
到
log4j.rootLogger= INFO,console,R,HTML,TTCC
以便log4j正确初始化。