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

查看:22
本文介绍了请正确初始化 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 找不到记录器 (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 Developer's Guide 并根据它们

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 中没有找到 log4j.properties.

I didn't find log4j.properties in the 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/logging/log4j/tags/v1_2_9/docs/TROUBLESHOOT.html

使用 appender 将日志输出写入目标.如果没有附加程序附加到一个类别或其任何祖先,您将在尝试登录时收到以下消息:

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

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

您可以在 log4j 文档,基本上是在文件的开头添加这样简单的内容:

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 的 appender;还要注意您提供的级别根记录器,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天全站免登陆