请正确初始化log4j系统。运行网络服务时
也许问这个看起来很傻,但我很困惑。我提到了配置Log4j属性,但它似乎没有帮助。
我编写了一个简单的 Web 服务 HelloWorld。在运行它时,我收到如下错误:
log4j:WARN 找不到记录器 (org.apache.axis.transport.http.AxisServlet) 的附加程序。 log4j:WARN 请正确初始化log4j系统。
我不知道为什么会这样。
我正在使用 Eclipse 生成 Web 服务并部署在 Tomcat 6.0 中。我检查 Axis 开发人员指南 并根据它们
log4j.configuration=log4j.properties 使用此系统属性指定 Log4J 配置文件的名称。如果未指定,则默认配置文件为 log4j.properties。 axis.jar 中提供了 log4j.properties 文件。
我在 axis.jar
中没有找到 log4j.properties。
对此有什么帮助吗?
Maybe it looks silly to ask this but I am confused. I referred to Configuring Log4j property but it doesn't seem to help.
I have written a simple web service HelloWorld. And while running it I am getting the error something like this :
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.
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
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.
I didn't find log4j.properties in the axis.jar
.
Any help on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这些消息非常棘手,以至于人们创建了此错误报告让它更清楚。
它们的棘手之处在于,如果 Log4j 找不到其
log4j.properties
(或log4j.xml
)文件,则会写入警告,但也 如果文件很好,但从配置的角度来看其内容不完整。以下段落摘自 log4j 的故障排除指南:
您可以在 log4j 文档;基本上,通过在文件开头添加这样简单的内容:
这应该清除启动时收到的那些
WARN
消息。(确保您还没有名为stdout
的appender
还要注意您为根记录器指定的级别;debug
将非常冗长,并且应用程序中的每个库都会如此。开始向控制台写入内容。)至于
log4j.properties
/log4j.xml
文件,我建议您将此文件放在/WEB-INF/classes
中,因为它很重要它暴露了不同的调整(激活/停用日志、更改日志级别等)。您也可以将其放在classpath
的 JAR 中(如您在评论中指定的那样),但它将包含在存档中(希望位于存档内的正确位置),并且不会被就像在/WEB-INF/classes
中一样易于处理。Those messages are something tricky, enough so that people created this bug report to make it clearer.
What's tricky about them is that the warnings are written if Log4j can't find its
log4j.properties
(orlog4j.xml
) file, but also if the file is fine and dandy but its contents are not complete from a configuration point of view.The following paragraph is taken from the log4j's troubleshooting guide:
You can find info on how to configure the root logger (
log4j.rootLogger
) in the log4j documentation; basically, by adding something as simple as this at the beginning of the file:This should clear those
WARN
messages you get on startup. (Make sure you don't already have anappender
namedstdout
. Also be careful 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.)As for the
log4j.properties
/log4j.xml
file, 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 theclasspath
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.properties
。You have to create your own
log4j.properties
in the classpath folder.好吧,如果您已经创建了 log4j.properties,您可以将其路径添加到类路径中,以便在执行过程中找到它。
是的,该东西将在类路径中搜索该文件。
既然您说您查看了 axis 但没有找到,我假设您没有 log4j.properties,所以这是一个粗略但完整的示例。
在某处创建它并添加到您的类路径中。例如,在 c:/proj/resources/log4j.properties
在您的类路径中,您只需添加 ......;c:/proj/resources
Well, if you had already created the log4j.properties you would add its path to the classpath so it would be found during execution.
Yes, the thingy will search for this file in the classpath.
Since you said you looked into axis and didnt find one, I am assuming you dont have a log4j.properties, so here's a crude but complete example.
Create it somewhere and add to your classpath. Put it for example, in c:/proj/resources/log4j.properties
In your classpath you simple add .......;c:/proj/resources
如果您的类中存在以下语句,那么您的 log4j.properties 应该位于 java source(src) 文件夹中,如果它是 jar 可执行文件,则应该打包在 jar 中而不是单独的文件中。
谢谢,
If the below statment is present in your class then your log4j.properties should be in java source(src) folder , if it is jar executable it should be packed in jar not a seperate file.
Thanks,
警告无法找到记录器的附加程序意味着您正在使用
log4j
日志系统,但您尚未在配置文件中添加任何 Appender(例如 FileAppender、ConsoleAppender、SocketAppender、SyslogAppender 等)或配置文件丢失。配置 log4j 的方法有三种:使用属性文件 (
log4j.properties
)、使用 XML 文件和通过 Java 代码 (rootLogger.addAppender(new NullAppender());
)。如果您有属性文件(例如,安装 Solr 时),则需要将此文件放在 classpath 目录。
类路径
以下是一些如何确定类路径值的命令建议:
或者从 Java:
System.getProperty("java.class.path")
。Tomcat
如果您使用 Tomcat,您可以将
log4j.properties
放入:/usr/share/tomcat?/lib/
或/var/lib/ tomcat?/webapps/*/WEB-INF/lib/
文件夹。Solr
作为参考,Solr
log4j.properties
如下所示:Warning No appenders could be found for logger means that you're using
log4j
logging system, but you haven't added any Appenders (such as FileAppender, ConsoleAppender, SocketAppender, SyslogAppender, etc.) into your configuration file or the configuration file is missing.There are three ways to configure log4j: with a properties file (
log4j.properties
), with an XML file and through Java code (rootLogger.addAppender(new NullAppender());
).If you've property file present (e.g. when installing Solr), you need to place this file within your classpath directory.
classpath
Here are some command suggestions how to determine your classpath value:
or from Java:
System.getProperty("java.class.path")
.Tomcat
If you're using Tomcat, you may place your
log4j.properties
into:/usr/share/tomcat?/lib/
or/var/lib/tomcat?/webapps/*/WEB-INF/lib/
folder.Solr
For the reference, Solr
log4j.properties
looks like:如果您使用的是
Logger.getLogger(ClassName.class)
,则将log4j.properties
文件放入类路径中:If you are using
Logger.getLogger(ClassName.class)
then place yourlog4j.properties
file in your class path:您可以像上面的答案一样配置 log4j.properties,或者使用 org.apache.log4j.BasicConfigurator
因此在表下配置:
You can configure log4j.properties like above answers, or use
org.apache.log4j.BasicConfigurator
So under the table, configure do: