首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Apache/Tomcat上的Log4j不工作

Apache/Tomcat上的Log4j不工作
EN

Stack Overflow用户
提问于 2012-04-21 02:55:23
回答 4查看 14.6K关注 0票数 1

我正在做一个Java Servlet项目。我正在尝试使用log4j来记录异常、方法输入和输出等。

我已经添加了Jars文件和log4j.properties文件。

如果我使用Main测试来自测试类的Log4j,它可以正常工作。但是当我使用Servlet项目时,不会创建日志文件。

我正在与Apache和Tomcat一起开发Eclipse

首先,我认为问题出在log4j.properties文件上。我从src目录移动到Webcontent目录。然后,我再次移动到Webcontent目录中的classes目录。但我不工作。

这是我的log4j.properties文件:

代码语言:javascript
运行
复制
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

这是控制台:

代码语言:javascript
运行
复制
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.

我不知道该怎么做。你能帮帮我吗?

对不起,我的英语很差

EN

回答 4

Stack Overflow用户

发布于 2012-04-21 03:30:04

首先将log4j.properties放入您的src文件夹中。如果您使用Maven,请将其放在src/main/resources.下如果log4j.jar (使用版本1.2.16)在类路径内,则将自动检测该文件。

然后使用以下命令编辑行:"debug,info,error,...“设置为"debug“或"info",因为一次只能有一个日志级别:

代码语言:javascript
运行
复制
log4j.logger.fnet3CustomerAreaMobile = debug, fnet3CustomerAreaMobile

第二个值必须是附加器的名称。

检查您的lib目录中是否有以下jars: Apacheslf4j-(添加slf4j),apache (从slf4j重定向到log4j)和apache(重定向到slf4j)。使用1.6.4 (newest),SLF4J版本也必须兼容。SLF4J是通过添加和删除正确的jars (可悲的是)自动配置的。只添加上面提到的jars。

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2012-04-21 03:01:55

请检查您的日志。尤其是最后两行:

代码语言:javascript
运行
复制
...
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
...

我非常确定您在类路径中丢失了一些库。

票数 0
EN

Stack Overflow用户

发布于 2012-04-21 03:18:47

看看这个,看看是否有帮助。

http://www.slf4j.org/codes.html#StaticLoggerBinder

无法加载类org.slf4j.impl.StaticLoggerBinder

当无法将org.slf4j.impl.StaticLoggerBinder类加载到内存中时,会报告此错误。当在类路径上找不到合适的SLF4J绑定时,就会发生这种情况。在类路径上放置slf4j-nop.jar、slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar或logback-classic.jar中的一个(且只有一个)应该可以解决问题。

从1.6.0开始,在SLF4J版本1.6中,在没有绑定的情况下,SLF4J将默认使用无操作(NOP)记录器实现。

您可以从项目下载页面下载SLF4J绑定。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10251941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档