在 Java 中初始化和使用 Log4J
我需要知道如何在java中初始化和使用Log4j...... 当我尝试使用它时,出现以下错误
log4j:WARN No Appender can be find for logger (Main)。 log4j:WARN 请正确初始化 log4j 系统。
I need to know how to initialise and use Log4j in java....
When i try to use it i get the following error
log4j:WARN No appenders could be found for logger (Main).
log4j:WARN Please initialize the log4j system properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将
log4j.properties
放入src
文件夹中,系统会自动检查 log4j 配置。默认配置可能如下所示。否则,您可以通过编程方式调用默认配置。
摘自 Apache log4j 的简短介绍文档。在提出多余的问题之前,您应该先查找类似的问题。
考虑切换到 SLF4J 这使您可以轻松切换日志记录实现。
You could place a
log4j.properties
into yoursrc
folder, this is automatically checked for log4j configuration. A default configuration could look like this.Otherwise you could call the default configuration programmatically.
Taken from the short introduction document of Apache log4j. You should look for similiar questions before asking them redudant.
Consider to switch to SLF4J which enables you the possibilities to switch the logging implementation easily.
首先,阅读以下内容:http://logging.apache.org/log4j/1.2/manual。 html
不久,当您运行 JVM 时,会缺少以下属性:
-Dlog4j.configuration=mylog4jconfig.xml
但是:您的问题表明您刚刚开始使用 log4j。请注意,它的作者 Ceki Gülcü 已经过时了,他为 java 实现了新的记录器并建议人们使用它。请参阅 Logback (http://logback.qos.ch/) 和 SLF4J
First, read this: http://logging.apache.org/log4j/1.2/manual.html
Shortly the following property is missing when you are running JVM:
-Dlog4j.configuration=mylog4jconfig.xml
BUT: your question shows that you are just starting using log4j. Please note that it is already obsolete by its author, Ceki Gülcü, that implemented new logger for java and recommends people to use it. See Logback (http://logback.qos.ch/) and SLF4J
您需要在类路径中包含 log4j.properties 文件。
You need to have the log4j.properties file in your classpath.