如何配置log4j和Selenium Grid?

发布于 2024-10-27 08:58:24 字数 318 浏览 3 评论 0原文

当我使用 Ant 启动 Grid hub 时,默认情况下日志记录全部在控制台上。我想知道是否有一种方法可以更改 Selenium Grid 的 build.xml 文件并在其中包含 log4j 记录器。据我所知,我可以使用 -logfile 选项为 Ant 本身指定一个日志文件。但这会导致每次启动网格时日志文件都被覆盖。我想确保日志文件在达到阈值后自动重命名,以便更好地维护。任何帮助,如果可能的话,一些关于如何做到这一点的示例将不胜感激(我是使用 log4j 的新手,这就是为什么我要求一些示例来满足此特定需求)。

When I launch a Grid hub using Ant, the logging is all by default on the console. I would like to know if there is a way wherein I can alter the build.xml file of Selenium Grid and include a log4j logger into it. I understand that I can specify a log file to Ant itself using the -logfile option. But this would cause the log file to be overwritten everytime the grid is launched. I want to ensure that the log files are automatically renamed after a threshold is reached for better maintenance. Any help and if possible some examples on how to do it would be greatly appreciated (I am new to using log4j which is why I am asking for some sample for this specific need).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷默言语 2024-11-03 08:58:24

启动 Selenium 时,您需要指定 Log4j 存档及其配置文件的位置。在以下示例中,我更新了类路径以加载位于 /etc/selenium 目录中的 log4j.hub.properties 配置文件和 log4j.properties 文件。 jar 位于 /usr/lib/selenium 目录中。我还设置了一些额外的日志文件:

java -classpath /etc/selenium:/usr/lib/selenium/log4j.jar:/usr/lib/selenium/selenium-server-standalone.jar -Dlog4j.configuration=log4j.hub.properties org.openqa.grid.selenium.GridLauncher -role hub -log /var/log/selenium/hub.debug.log > /var/log/selenium/hub.output.log 2> /var/log/selenium/hub.error.log &

然后您可以使用类似以下内容来实现您正在寻找的内容:

log4j.rootLogger=ALL, file

log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=/var/log/selenium/hub.log
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} <%p> <%t> %m%n

您可能需要查看 此页面了解有关 Selenium 日志记录如何工作的更多信息。

You need to specify the location of the Log4j archive as well as its configuration file when starting up Selenium. In the following example, I've updated the classpath to load the log4j.hub.properties configuration file located in the /etc/selenium directory and the log4j.jar located in the /usr/lib/selenium directory. I've also setup some additional log files:

java -classpath /etc/selenium:/usr/lib/selenium/log4j.jar:/usr/lib/selenium/selenium-server-standalone.jar -Dlog4j.configuration=log4j.hub.properties org.openqa.grid.selenium.GridLauncher -role hub -log /var/log/selenium/hub.debug.log > /var/log/selenium/hub.output.log 2> /var/log/selenium/hub.error.log &

Then you can have something like the following to achieve what you are looking for:

log4j.rootLogger=ALL, file

log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=/var/log/selenium/hub.log
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} <%p> <%t> %m%n

You might want to look at this page for more information about how Selenium logging is working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文