本文介绍了log4j在哪里/如何查找log4j.properties文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个简单的测试应用程序中尝试log4j。我在eclipse中创建了一个新的Java项目,并将log4j JAR(v1.2.16)添加到我的构建路径中。然后我创建一个打印Hello World的简单类。然后我使用log4j Logger 类来记录信息消息。当我运行应用程序时,我看到了日志消息,使用我认为是默认的appender和布局。大。我遇到的麻烦是添加我自己的配置。这就是我所做的:

I'm trying out log4j in a simple test app. I create a new Java project in eclipse and add the log4j JAR (v1.2.16) to my build path. I then create a simple class that prints Hello World. Then I use the log4j Logger class to log a info message. When I run the app, I see the log message, using what I assume is the default appender and layout. Great. What I'm having trouble with is adding my own configuration. This is what I've done:

创建一个带有自定义appender和日志级别的log4j.properties文件并将其放入src文件夹(在编译时将其复制到bin文件夹)。运行应用程序 - 无需更改。

Created a log4j.properties file with a custom appender and log level and placed it into the src folder (which upon compilation gets copied to the bin folder). Run the app - no change.

我尝试添加 PropertyConfigurator.configure(log4j.properties)。运行应用程序 - 没有变化。没有错误,但没有变化。

I try adding PropertyConfigurator.configure("log4j.properties"). Run the app - no change. No errors, but no change.

如何让log4j加载我的配置文件?

What do I have to do to get log4j to load my configuration file?

推荐答案

唉。我发现问题是eclipse导入了错误的 Logger 类。它导入了java.util.logging.Logger,当然它有自己的配置,与log4j不同。哦,希望其他人这样做,并通过阅读这个问题解决它。

Argh. I discovered the problem was that eclipse had imported the wrong Logger class. It had imported java.util.logging.Logger which of course has it's own configuration that is different from log4j. Oh well, hope somebody else does this and gets it solved by reading this question.

这篇关于log4j在哪里/如何查找log4j.properties文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:53