请正确初始化log4j系统。在运行Web服务时 [英] Please initialize the log4j system properly. While running web service

查看:1049
本文介绍了请正确初始化log4j系统。在运行Web服务时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问这个问题看起来很傻,但我很困惑。我提到了配置Log4j属性,但似乎没有帮助。

Maybe it looks silly to ask this but I am confused. I referred to Configuring Log4j property but it doesn't seem to help.

我写了一个简单的Web服务HelloWorld。在运行它时,我得到的错误是这样的:

I have written a simple web service HelloWorld. And while running it I am getting the error something like this :


log4j:WARN没有找到logger的追加器(org.apache。 axis.transport.http.AxisServlet)。
log4j:WARN请正确初始化log4j系统。

log4j:WARN No appenders could be found for logger (org.apache.axis.transport.http.AxisServlet). log4j:WARN Please initialize the log4j system properly.

我不确定为什么会发生这种情况。

I am not sure why its happening.

我使用Eclipse生成Web服务并部署在Tomcat 6.0中。我查看 Axis开发人员指南并根据他们

I am generating the web-service using Eclipse and deployed in Tomcat 6.0. I check on Axis Developer's Guide and according to them


log4j.configuration = log4j.properties
使用此系统属性指定Log4J配置文件的名称。如果未指定,则默认配置文件为log4j.properties。在axis.jar中提供了log4j.properties文件。

log4j.configuration=log4j.properties Use this system property to specify the name of a Log4J configuration file. If not specified, the default configuration file is log4j.properties. A log4j.properties file is provided in axis.jar.

我在 axis.jar 。

对此有何帮助?

推荐答案

这些消息很棘手,足以让人们创建它以使其更清晰:
https://issues.apache.org/bugzilla/show_bug.cgi?id=25747

Those messages are something tricky, enough so that people created this to make it clearer: https://issues.apache.org/bugzilla/show_bug.cgi?id=25747

什么是棘手的如果Log4j找不到它的 log4j.properties (或 log4j.xml )文件,则会写入警告,但如果文件很好,花花公子,但从配置的角度看它的内容是不完整的。

What's tricky about them is that the warnings are written if Log4j can't find its log4j.properties (or log4j.xml) file, but also if the file is fine and dandy but its content is not complete from a configuration point of view.

以下段落取自这里:
http://svn.apache.org/repos / ASF /日志/ log4j的/标签/ v1_2_9 /文档/烦恼HOOT.html

使用appender将记录输出写入目标。如果没有追加者附加到类别或其任何祖先,您将在尝试记录时收到以下消息:

log4j: No appenders could be found for category (some.category.name).
log4j: Please initialize the log4j system properly.

Log4j没有默认的记录目标。用户有责任确保所有类别都可以继承appender。这可以通过将appender附加到根类别来轻松实现。

您可以找到有关如何配置根记录器的信息(文档中的> log4j.rootLogger ),基本上在文件的开头添加一些简单的东西:

You can find info on how to configure the root logger (log4j.rootLogger) in the log4j documentation, basically adding something as simple as this at the beginning of the file:

log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

这应该清除那些您在启动时获得的WARN消息(确保您还没有名为 stdout 的追加器;还要注意您为根记录器提供的级别, debug 将非常冗长,你应用中的每个库都会开始向控制台写东西。

This should clear those WARN messages you get on startup (make sure you don't already have an appender named stdout; also be carefull of what level you give the root logger, debug will be very verbose and every library in your app will start writing stuff to the console).

至于 log4j.properties / log4j.xml ,我建议你把这个文件放在 / WEB-INF / classes 因为重要的是让它暴露出来进行不同的调整(激活/停用日志,更改日志级别等)。您也可以在类路径中的JAR中(如您在注释中指定的那样),但它将被包含在存档中(希望在存档中的正确位置)并且不会像在它中一样容易处理在 / WEB-INF / classes

As about the log4j.properties/log4j.xml, I suggest you place this file in /WEB-INF/classes as it is important to have it exposed for different tweaks (activating/deactivating logs, changing log levels etc). You can have it inside a JAR in the classpath also (as you specified in your comment), but it will be enclosed in the archive (hopefully in the right place inside the archive) and won't be as easy to handle as if it were in /WEB-INF/classes.

这篇关于请正确初始化log4j系统。在运行Web服务时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆