Java log4j:WARN 请正确初始化 log4j 系统

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29519850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:09:36  来源:igfitidea点击:

log4j:WARN Please initialize the log4j system properly

javaeclipseseleniumlogging

提问by AndersK

I am trying to learn selenium.

我正在努力学习硒。

I get following error message:

我收到以下错误消息:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfigfor more info.

log4j:WARN 找不到记录器 (org.apache.http.client.protocol.RequestAddCookies) 的附加程序。log4j:WARN 请正确初始化 log4j 系统。log4j:WARN 有关更多信息,请参阅 http://logging.apache.org/log4j/1.2/faq.html#noconfig

So, I have downloaded the file log4j.propertiesand I have googled on it and tried to implement the file in different ways in Eclipse but nothing worked out. I see that someone is saying:

因此,我已经下载了该文件log4j.properties并在其上进行了 google 搜索,并尝试在 Eclipse 中以不同的方式实现该文件,但没有任何结果。我看到有人在说:

Put a file named log4j.properties in the root of your classpath:

将名为 log4j.properties 的文件放在类路径的根目录中:

log4j.rootLogger = ALL, Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.conversionPattern=%m%n

Nothing else is needed. Log4j will discover it and configure itself.

不需要其他任何东西。Log4j 会发现它并自行配置。

But what do they mean by "in the root of your classpath"?

但是“在您的类路径的根目录中”是什么意思?

I work in Eclipse. So how do I find the root of the classpath in Eclipse?

我在 Eclipse 工作。那么如何在 Eclipse 中找到类路径的根目录呢?

回答by YosefY

Did you simply try to put it in your source folder? It should be copied automatically to your deployment folder on build. If you already tried, it may be your deployment rules that skip *.properties files...

您是否只是尝试将其放入源文件夹中?它应该在构建时自动复制到您的部署文件夹。如果您已经尝试过,则可能是您的部署规则跳过了 *.properties 文件...

Hope that will help you

希望能帮到你

回答by Nimisha

It looks like you need to add the location of your log4j.properties or log4j.xml file to the Classpath in Eclipse.

看起来您需要将 log4j.properties 或 log4j.xml 文件的位置添加到 Eclipse 中的类路径。

Make sure your project is open in Eclipse, then click on the "Run" menu at the top of Eclipse and click on the following:

确保您的项目在 Eclipse 中打开,然后单击 Eclipse 顶部的“运行”菜单并单击以下内容:

Run -> Run Configurations -> Classpath (tab) -> User Entries -> Advanced (button on the right) -> Add Folders ->then navigate to the folder that contains your log4j.properties file

运行 -> 运行配置 -> 类路径(选项卡) -> 用户条目 -> 高级(右侧按钮) -> 添加文件夹 -> 然后导航到包含 log4j.properties 文件的文件夹

Apply -> Run

应用 -> 运行

The error message should no longer appear.

错误消息不应再出现。

回答by Rinash

Delete the log4j.rar from your external Libraries

从外部库中删除 log4j.rar

steps: Right click on src-->BuildPath-->Configure Buildpath-->Libraries-->Select Log4j.rar and Remove it.

步骤: 右键src-->BuildPath-->Configure Buildpath-->Libraries-->选择Log4j.rar并删除。

For report generation, you need to add log4j for simply executing the script no need to add log4j.

对于报表生成,您需要添加 log4j 以执行脚本,无需添加 log4j。

Hope this will solve your problem

希望这能解决你的问题