我正在开发一个 Java Servlet 项目。我正在尝试使用 log4j 来记录异常、方法输入和输出等。
我已经添加了 Jars 文件和 log4j.properties 文件。
如果我使用 Main 从测试类测试 Log4j,它可以正常工作。但是当我使用 Servlet 项目时,并没有创建日志文件。
我正在使用 Apache 和 Tomcat 开发 Eclipse
首先,我认为问题出在 log4j.properties 文件上。我从 src 目录移动到 Webcontent 目录。然后我再次移动到 Webcontent 目录中的 classes 目录。但我不工作。
这是我的 log4j.properties 文件:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p %c{1}:%L - %m%n
log4j.appender.stdout.Threshold=debug
log4j.appender.stdout.Append=true
log4j.appender.FILEHIBERNATE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILEHIBERNATE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILEHIBERNATE.datePattern='.'yyyy-MM-dd
log4j.appender.FILEHIBERNATE.file =logs/Hibernate.log
log4j.appender.FILEHIBERNATE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [Level: %p]%m%n
log4j.appender.FILEHIBERNATE.Threshold=debug
log4j.appender.FILEHIBERNATE.Append=true
log4j.appender.springframework=org.apache.log4j.DailyRollingFileAppender
log4j.appender.springframework.layout=org.apache.log4j.PatternLayout
log4j.appender.springframework.datePattern='.'yyyy-MM-dd
log4j.appender.springframework.file =logs/springframework.log
log4j.appender.springframework.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [Level: %p]%m%n
log4j.appender.springframework.Threshold=debug
log4j.appender.springframework.Append=true
log4j.appender.fidely=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fidely.layout=org.apache.log4j.PatternLayout
log4j.appender.fidely.datePattern='.'yyyy-MM-dd
log4j.appender.fidely.file =logs/Fidely.log
log4j.appender.fidely.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [Level: %p]%m%n
log4j.appender.fidely.Threshold=info,debug
log4j.appender.fidely.Append=true
log4j.appender.fnet3CustomerAreaMobile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fnet3CustomerAreaMobile.layout=org.apache.log4j.PatternLayout
log4j.appender.fnet3CustomerAreaMobile.datePattern='.'yyyy-MM-dd
log4j.appender.fnet3CustomerAreaMobile.file =logs/customer_area_interfaces/fidelynet3CustomerAreaMobile.log
log4j.appender.fnet3CustomerAreaMobile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [Level: %p]%m%n
log4j.appender.fnet3CustomerAreaMobile.Threshold=debug,info,error
log4j.appender.fnet3CustomerAreaMobile.Append=true
log4j.appender.fnet3CustomerAreaMobileServlet=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fnet3CustomerAreaMobileServlet.layout=org.apache.log4j.PatternLayout
log4j.appender.fnet3CustomerAreaMobileServlet.datePattern='.'yyyy-MM-dd
log4j.appender.fnet3CustomerAreaMobileServlet.file =logs/customer_area_interfaces/mobile/fidelynet3CustomerAreaMobile.log
log4j.appender.fnet3CustomerAreaMobileServlet.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [Level: %p]%m%n
log4j.appender.fnet3CustomerAreaMobileServlet.Threshold=debug,info,error
log4j.appender.fnet3CustomerAreaMobileServlet.Append=true
log4j.logger.net.sf.hibernate = DEBUG, FILEHIBERNATE
log4j.logger.hibernate = DEBUG, FILEHIBERNATE
log4j.logger.org.hibernate = DEBUG, FILEHIBERNATE
log4j.logger.org.springframework = debug, springframework
log4j.logger.fidely = info, fidely
log4j.logger.fnet3CustomerAreaMobile = debug, info, error, fnet3CustomerAreaMobile
log4j.logger.fnet3CustomerAreaMobileServlet = debug, info, error, fnet3CustomerAreaMobileServlet
log4j.rootLogger = debug
这是控制台:
log4j:ERROR Could not find value for key log4j.appender.info
log4j:ERROR Could not instantiate appender named "info".
log4j:ERROR Could not find value for key log4j.appender.error
log4j:ERROR Could not instantiate appender named "error".
log4j:ERROR Could not find value for key log4j.appender.info
log4j:ERROR Could not instantiate appender named "info".
log4j:ERROR Could not find value for key log4j.appender.error
log4j:ERROR Could not instantiate appender named "error".
log4j:ERROR Could not find value for key log4j.appender.info
log4j:ERROR Could not instantiate appender named "info".
log4j:ERROR Could not find value for key log4j.appender.error
log4j:ERROR Could not instantiate appender named "error".
log4j:ERROR Could not find value for key log4j.appender.info
log4j:ERROR Could not instantiate appender named "info".
log4j:ERROR Could not find value for key log4j.appender.error
log4j:ERROR Could not instantiate appender named "error".
log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
我不知道该怎么做。你能帮助我吗?
对不起我糟糕的英语