我是在Linux下的jdk里面运行java程序,出现一下的错误:
log4j:ERROR Could not find value for key log4j.appender.stdout□R
log4j:ERROR Could not instantiate appender named "stdout□R".
log4j:ERROR Could not find value for key log4j.appender.stdout□R
log4j:ERROR Could not instantiate appender named "stdout□R".
log4j:WARN No appenders could be found for logger (LogTest).
log4j:WARN Please initialize the log4j system properly.
程序代码如下:
import org.apache.log4j.*; public class LogTest { static Logger logger = Logger.getLogger(LogTest.class.getName()); public static void main(String[] args) { PropertyConfigurator.configure("/tmp/log4j.properties"); logger.debug("Debug ..."); logger.info("Info ..."); logger.warn("Warn ..."); logger.error("Error ..."); }}
log4j:ERROR Could not find value for key log4j.appender.stdout□R
log4j:ERROR Could not instantiate appender named "stdout□R".
log4j:ERROR Could not find value for key log4j.appender.stdout□R
log4j:ERROR Could not instantiate appender named "stdout□R".
log4j:WARN No appenders could be found for logger (LogTest).
log4j:WARN Please initialize the log4j system properly.
程序代码如下:
import org.apache.log4j.*; public class LogTest { static Logger logger = Logger.getLogger(LogTest.class.getName()); public static void main(String[] args) { PropertyConfigurator.configure("/tmp/log4j.properties"); logger.debug("Debug ..."); logger.info("Info ..."); logger.warn("Warn ..."); logger.error("Error ..."); }}
log4j:WARN Please initialize the log4j system properly
这个是什么问题啊
指定了log4j.properties的位置。/tmp/log4j.properties 中写入下面内容:
log4j.rootCategory=INFO,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%p] {%t} %C.%M(%L) | %m%n运行一切正常。
log4j:WARN Please initialize the log4j system properly
是说你缺少一个名字为LogTest的定义log4j.logger.LogTest=info,lt
log4j.appender.lt=org.apache.log4j.DailyRollingFileAppender
log4j.appender.lt.File=d:\\lt.log
log4j.appender.lt.DatePattern='.'yyyy-MM-dd
log4j.appender.lt.layout=org.apache.log4j.PatternLayout
log4j.appender.lt.layout.ConversionPattern=%p,%-d{yyyy-MM-dd HH:mm:ss,S}, - ,%m%n