<legend id='bqGIf'><style id='bqGIf'><dir id='bqGIf'><q id='bqGIf'></q></dir></style></legend>

    1. <small id='bqGIf'></small><noframes id='bqGIf'>

    2. <tfoot id='bqGIf'></tfoot>
      <i id='bqGIf'><tr id='bqGIf'><dt id='bqGIf'><q id='bqGIf'><span id='bqGIf'><b id='bqGIf'><form id='bqGIf'><ins id='bqGIf'></ins><ul id='bqGIf'></ul><sub id='bqGIf'></sub></form><legend id='bqGIf'></legend><bdo id='bqGIf'><pre id='bqGIf'><center id='bqGIf'></center></pre></bdo></b><th id='bqGIf'></th></span></q></dt></tr></i><div id='bqGIf'><tfoot id='bqGIf'></tfoot><dl id='bqGIf'><fieldset id='bqGIf'></fieldset></dl></div>

        <bdo id='bqGIf'></bdo><ul id='bqGIf'></ul>

        如何在 TestNG 报告中包含 Log4j2 消息

        时间:2023-05-28
            <tbody id='VMNf0'></tbody>
            <bdo id='VMNf0'></bdo><ul id='VMNf0'></ul>
            <legend id='VMNf0'><style id='VMNf0'><dir id='VMNf0'><q id='VMNf0'></q></dir></style></legend>

              <tfoot id='VMNf0'></tfoot>

                <small id='VMNf0'></small><noframes id='VMNf0'>

                • <i id='VMNf0'><tr id='VMNf0'><dt id='VMNf0'><q id='VMNf0'><span id='VMNf0'><b id='VMNf0'><form id='VMNf0'><ins id='VMNf0'></ins><ul id='VMNf0'></ul><sub id='VMNf0'></sub></form><legend id='VMNf0'></legend><bdo id='VMNf0'><pre id='VMNf0'><center id='VMNf0'></center></pre></bdo></b><th id='VMNf0'></th></span></q></dt></tr></i><div id='VMNf0'><tfoot id='VMNf0'></tfoot><dl id='VMNf0'><fieldset id='VMNf0'></fieldset></dl></div>
                • 本文介绍了如何在 TestNG 报告中包含 Log4j2 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望在所有测试用例的 TestNG 报告中提供 Log4j2 日志记录信息.

                  I would like to have the Log4j2 logging information available in the TestNG reports for all of the test cases.

                  TestNG 使用一个名为 Reporter.java 的特殊记录器类,它跟踪日志输出并将其保存在其结果 XML 中.

                  TestNG uses a special logger class called Reporter.java that keeps track of the log output and saves it in its results XML.

                  在 log4j 中,可以简单地创建一个路由到 Reporter 并注册它的 appender 实现.

                  In log4j it was possible to simply create an appender implementation that routes to Reporter and register it.

                  使用 Log4j2 中的新 Logger API,很难找到有关如何完成此操作的信息.我有一些信息可以使用 Log4j 而不是使用 Log4j2 来完成.

                  With the new Logger API in Log4j2 it has been difficult to find information on how to accomplish this. I have some information to get this done using Log4j but not with Log4j2.

                  推荐答案

                  据我所知,你只需要实现一个简单的 Appender.比如:

                  From what I can tell you just need to implement a simple Appender. Something like:

                  @Plugin(name="Reporter", category ="Core", elementType="appender", printObject=true)
                  public class ReporterAppender extends AbstractAppender {
                  
                      private ReporterAppender(final String name, final Layout layout) {
                          super(name, null, layout, false);
                      }
                  
                      @Override
                      public void append(final LogEvent event) {
                          final Layout<? extends Serializable> layout = getLayout();
                          if (layout != null && layout instanceof AbstractStringLayout) {
                               Reporter.log(((AbstractStringLayout) layout).toSerializable(event));
                          } else {
                               Reporter.log(event.getMessage().getFormattedMessage();            }
                  
                      @PluginFactory
                      public static ReporterAppender createAppender(
                          @PluginAttribute("name") @Required(message = "A name for the Appender must be specified") final String name,
                          @PluginElement("Layout") Layout<? extends Serializable> layout) {
                          return new ReporterAppender(name, layout);
                      }
                  }
                  

                  这篇关于如何在 TestNG 报告中包含 Log4j2 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Selenium 中为每个元素使用多个定位器的优缺点? 下一篇:Selenium - 完整的ajax加载自动滚动到页面底部

                  相关文章

                  <tfoot id='3l6Ed'></tfoot>
                    • <bdo id='3l6Ed'></bdo><ul id='3l6Ed'></ul>

                    <small id='3l6Ed'></small><noframes id='3l6Ed'>

                  1. <i id='3l6Ed'><tr id='3l6Ed'><dt id='3l6Ed'><q id='3l6Ed'><span id='3l6Ed'><b id='3l6Ed'><form id='3l6Ed'><ins id='3l6Ed'></ins><ul id='3l6Ed'></ul><sub id='3l6Ed'></sub></form><legend id='3l6Ed'></legend><bdo id='3l6Ed'><pre id='3l6Ed'><center id='3l6Ed'></center></pre></bdo></b><th id='3l6Ed'></th></span></q></dt></tr></i><div id='3l6Ed'><tfoot id='3l6Ed'></tfoot><dl id='3l6Ed'><fieldset id='3l6Ed'></fieldset></dl></div>
                    <legend id='3l6Ed'><style id='3l6Ed'><dir id='3l6Ed'><q id='3l6Ed'></q></dir></style></legend>