获取执行日志的电子邮件,即使没有错误存在。

huangapple go评论88阅读模式
英文:

Get email with execution log even when no error exists

问题

My requirements:

  1. 如果在执行过程中出现错误,我需要发送一封电子邮件,其中包含错误日志以及具有日志级别 >= INFO 的先前日志。 我的当前配置满足此要求。
  2. 如果执行中没有错误,我需要电子邮件包含执行过程中记录的所有消息,其中日志级别 >= INFO。 需要帮助。 我当前的配置不满足此要求。

我在我的Maven项目中有以下的log4j2 xml文件:

<Configuration status="INFO">
	<Properties>
		...(其他属性)
	</Properties>
	<Appenders>
		...(其他Appenders)
	</Appenders>
	<Loggers>
		...(其他Loggers)
	</Loggers>
</Configuration>

在执行以下代码后:

private static Logger log = LogManager.getLogger("test");
log.trace("trace");
log.debug("debug");
log.info("info");
log.warn("warn");
log.error("error");
log.fatal("fatal");

如预期的那样,我收到了两封电子邮件,内容如下:

第一封电子邮件(由于记录器的日志级别设置为INFO,trace和debug被忽略):

2020-07-23 03:18:31.780 [main] INFO  test - info
2020-07-23 03:18:31.789 [main] WARN  test - warn
2020-07-23 03:18:31.790 [main] ERROR test - error

第二封电子邮件:

2020-07-23 03:18:31.790 [main] FATAL test - fatal

到目前为止,一切都按预期工作。

问题:在执行以下代码后,我没有收到任何电子邮件(因为没有日志级别为ERROR或FATAL的日志):

private static Logger log = LogManager.getLogger("test");
log.trace("trace");
log.debug("debug");
log.info("info");
log.warn("warn");

在这种情况下,是否可能收到包含以下内容的单封电子邮件? 如果是,如何实现?

2020-07-23 03:18:31.780 [main] INFO  test - info
2020-07-23 03:18:31.789 [main] WARN  test - warn

已解决:
如@RemkoPopma所建议,我必须决定在执行期间没有错误的情况下电子邮件的触发条件。 我分析了我的日志并检查了每当执行没有问题/错误时,我都会发送包含文本“Suite execution completed”的日志消息。 因此,我使用了SMTP appender的复合过滤器,如下所示:

<SMTP name="mailLog" subject="${mailSubject}" to="${recipients}"
    from="${sender}" smtpHost="${host}" smtpPort="${port}"
    smtpUsername="${username}" smtpPassword="${password}"
    buffersize="${bufferSize}" smtpProtocol="${protocol}"
    ignoreExceptions="false" smtpdebug="true">
    <PatternLayout pattern="${standardPattern}" />
    <Filters>
        <ThresholdFilter level="error" onMatch="ACCEPT"
         onMismatch="NEUTRAL" />
        <RegexFilter regex="^.*Suite execution completed.*$"
         onMatch="ACCEPT" onMisMatch="DENY" />
    </Filters>
</SMTP>

解释:

  • 如果在执行过程中出现错误,则阈值过滤器接受日志并发送包含该错误日志以及缓冲区中的所有其他日志(满足我的要求1)的电子邮件。
  • 如果在执行过程中没有错误,那么日志消息(级别<ERROR)将通过Threshold过滤器(onMisMatch=NEUTRAL)传递到序列中的下一个过滤器,即RegexFilter。 RegexFilter将不断拒绝(并将它们添加到缓冲区)日志,直到我们得到包含文本“Suite execution completed”的日志为止。 一
英文:

My requirements:

  1. If there an error is encountered during the execution, I need to send an email having the error log as well as previous logs with log levels >= INFO. My current configuration satisfy this requirement.
  2. If there are no errors in the execution, I need the email to have all the messages logged during the execution with log levels >=INFO. Need help here. My current configuration does not satisfy this requirement.

I have the following log4j2 xml file in my maven project:

&lt;Configuration status=&quot;INFO&quot;&gt;
	&lt;Properties&gt;
		&lt;Property name=&quot;standardPattern&quot;&gt;%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n&lt;/Property&gt;
		&lt;Property name=&quot;mailSubject&quot;&gt;Execution Log&lt;/Property&gt;
		&lt;Property name=&quot;recipients&quot;&gt;xxxx@gmail.com&lt;/Property&gt;
		&lt;Property name=&quot;sender&quot;&gt;xx@gmail.com&lt;/Property&gt;
		&lt;Property name=&quot;host&quot;&gt;smtp.gmail.com&lt;/Property&gt;
		&lt;Property name=&quot;port&quot;&gt;587&lt;/Property&gt;
		&lt;Property name=&quot;username&quot;&gt;xx@gmail.com&lt;/Property&gt;
		&lt;Property name=&quot;protocol&quot;&gt;smtp&lt;/Property&gt;
		&lt;Property name=&quot;password&quot;&gt;secret&lt;/Property&gt;
		&lt;Property name=&quot;bufferSize&quot;&gt;512&lt;/Property&gt;
	&lt;/Properties&gt;
	&lt;Appenders&gt;
		&lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;
			&lt;PatternLayout pattern=&quot;${standardPattern}&quot; /&gt;
		&lt;/Console&gt;
		&lt;SMTP name=&quot;mailLog&quot; subject=&quot;${mailSubject}&quot; to=&quot;${recipients}&quot;
			from=&quot;${sender}&quot; smtpHost=&quot;${host}&quot; smtpPort=&quot;${port}&quot;
			smtpUsername=&quot;${username}&quot; smtpPassword=&quot;${password}&quot;
			buffersize=&quot;${bufferSize}&quot; smtpProtocol=&quot;${protocol}&quot;
			ignoreExceptions=&quot;false&quot; smtpdebug=&quot;true&quot;&gt;
			&lt;PatternLayout pattern=&quot;${standardPattern}&quot; /&gt;
			&lt;ThresholdFilter level=&quot;error&quot; onMatch=&quot;NEUTRAL&quot;
				onMismatch=&quot;DENY&quot; /&gt;
		&lt;/SMTP&gt;
		&lt;Async name=&quot;asyncMail&quot;&gt;
			&lt;AppenderRef ref=&quot;mailLog&quot; /&gt;
		&lt;/Async&gt;
	&lt;/Appenders&gt;
	&lt;Loggers&gt;
		&lt;Root level=&quot;info&quot;&gt;
			&lt;AppenderRef ref=&quot;Console&quot; /&gt;
		&lt;/Root&gt;
		&lt;Logger name=&quot;test&quot; level=&quot;info&quot; additivity=&quot;false&quot;&gt;
			&lt;AppenderRef ref=&quot;Console&quot; /&gt;
			&lt;AppenderRef ref=&quot;asyncMail&quot;/&gt;
		&lt;/Logger&gt;
	&lt;/Loggers&gt;
&lt;/Configuration&gt;

On executing the following code:

private static Logger log = LogManager.getLogger(&quot;test&quot;);
log.trace(&quot;trace&quot;);
log.debug(&quot;debug&quot;);
log.info(&quot;info&quot;);
log.warn(&quot;warn&quot;);
log.error(&quot;error&quot;);
log.fatal(&quot;fatal&quot;);

As expected, I get 2 emails with the following contents:

1st email(trace and debug were ignored as the logger's log level is set to info):

2020-07-23 03:18:31.780 [main] INFO  test - info
2020-07-23 03:18:31.789 [main] WARN  test - warn
2020-07-23 03:18:31.790 [main] ERROR test - error

2nd email:

2020-07-23 03:18:31.790 [main] FATAL test - fatal

Until now, everything works as expected.

Issue: On executing the following code, I did not receive any email(because there were no logs with level = ERROR or FATAL)

private static Logger log = LogManager.getLogger(&quot;test&quot;);
log.trace(&quot;trace&quot;);
log.debug(&quot;debug&quot;);
log.info(&quot;info&quot;);
log.warn(&quot;warn&quot;);

Is such a case, is it possible to get a single email having the following contents? If yes, how?

2020-07-23 03:18:31.780 [main] INFO  test - info
2020-07-23 03:18:31.789 [main] WARN  test - warn

RESOLVED:
As told by @RemkoPopma, I had to decide the trigger for the email in case there was no error during the execution. I analysed my logs and checked that whenever the execution gets completed without any issues/errors, I send the log message Suite execution completed. So, keeping that in mind, I ended by using the composite filter for the SMTP appender as shown below:

&lt;SMTP name=&quot;mailLog&quot; subject=&quot;${mailSubject}&quot; to=&quot;${recipients}&quot;
from=&quot;${sender}&quot; smtpHost=&quot;${host}&quot; smtpPort=&quot;${port}&quot;
smtpUsername=&quot;${username}&quot; smtpPassword=&quot;${password}&quot;
buffersize=&quot;${bufferSize}&quot; smtpProtocol=&quot;${protocol}&quot;
ignoreExceptions=&quot;false&quot; smtpdebug=&quot;true&quot;&gt;
    &lt;PatternLayout pattern=&quot;${standardPattern}&quot; /&gt;
    &lt;Filters&gt;
	    &lt;ThresholdFilter level=&quot;error&quot; onMatch=&quot;ACCEPT&quot;
	     onMismatch=&quot;NEUTRAL&quot; /&gt;
	    &lt;RegexFilter regex=&quot;^.*Suite execution completed.*$&quot;
	     onMatch=&quot;ACCEPT&quot; onMisMatch=&quot;DENY&quot; /&gt;
    &lt;/Filters&gt;
&lt;/SMTP&gt;

Explanation:

  • In case there is an error during the execution, the threshold filter accepts the log and sends the email displaying that error log along with all the other previous logs(satisfying my requirement 1)
  • In case there is no error during the execution, then log messages(level<ERROR) pass through the Threshold filter(onMisMatch=NEUTRAL) to the next filter in sequence i.e., RegexFilter. The RegexFilter will keep on denying(and adding them to buffer) the logs unless we get a log containing the text Suite execution completed. Once this log is encountered, an email is trigerred containing the final log message along with all the previous logs stored in the buffer.

The following was sent to me after the execution got completed without any error:

2020-07-23 17:08:44.269 [main] INFO  Expedia - Suite execution started
2020-07-23 17:08:44.283 [main] INFO  Expedia - Launching the &quot;chrome&quot; Browser
2020-07-23 17:08:49.590 [main] INFO  Expedia - Maximizing browser window
2020-07-23 17:08:51.865 [main] INFO  Expedia - Reading test data from the excel file at locaton - E:\Testing\WebTesting\WebTesting\src\test\resources\testData\oneWayFlight_checkEconomyClassResultsDefaultDate.xlsx
2020-07-23 17:08:55.632 [main] INFO  Expedia - Deleting all the cookies
2020-07-23 17:08:55.649 [main] INFO  Expedia - Navigating to URL - https://www.expedia.co.in/
2020-07-23 17:09:06.845 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:09:06.846 [main] INFO  Expedia - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;STARTING TEST&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
2020-07-23 17:09:06.847 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:09:06.848 [main] INFO  Expedia - Starting Test execution for the test &quot;oneWayFlight_checkEconomyClassResultsDefaultDate&quot; with test data - {Leaving from=Mumbai, Going to=Chennai, Departure Date=29/12/20, Travel Class=Economy, Adults=2.0, Children=1.0, Infants=1.0}
2020-07-23 17:09:07.281 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //span[text()=&#39;Flights&#39;]]
2020-07-23 17:09:08.131 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //span[text()=&#39;One-way&#39;]]
2020-07-23 17:09:12.832 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: [data-stid=&#39;location-field-leg1-origin-menu-trigger&#39;]]
2020-07-23 17:09:13.663 [main] INFO  Expedia - Sending text &quot;Mumbai&quot; to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: location-field-leg1-origin]
2020-07-23 17:09:14.981 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //strong[contains(text(),&#39;Mumbai&#39;)]]
2020-07-23 17:09:15.377 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: [data-stid=&#39;location-field-leg1-destination-menu-trigger&#39;]]
2020-07-23 17:09:15.652 [main] INFO  Expedia - Sending text &quot;Chennai&quot; to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: location-field-leg1-destination]
2020-07-23 17:09:18.038 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //strong[contains(text(),&#39;Chennai&#39;)]]
2020-07-23 17:09:18.758 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: d1-btn]
2020-07-23 17:09:19.151 [main] INFO  Expedia - Scrolling the page to bring the object &quot;[[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker]&quot; in the visible area
2020-07-23 17:09:20.778 [main] INFO  Expedia - The text &quot;July 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:09:20.850 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button.uitk-button.uitk-button-small.uitk-flex-item.uitk-button-paging:last-child]
2020-07-23 17:09:21.069 [main] INFO  Expedia - The text &quot;August 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:09:21.106 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button.uitk-button.uitk-button-small.uitk-flex-item.uitk-button-paging:last-child]
2020-07-23 17:09:21.279 [main] INFO  Expedia - The text &quot;September 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:09:21.318 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button.uitk-button.uitk-button-small.uitk-flex-item.uitk-button-paging:last-child]
2020-07-23 17:09:21.481 [main] INFO  Expedia - The text &quot;October 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:09:21.519 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button.uitk-button.uitk-button-small.uitk-flex-item.uitk-button-paging:last-child]
2020-07-23 17:09:21.796 [main] INFO  Expedia - The text &quot;November 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:09:21.935 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button.uitk-button.uitk-button-small.uitk-flex-item.uitk-button-paging:last-child]
2020-07-23 17:09:22.498 [main] INFO  Expedia - The text &quot;December 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:09:22.710 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //div[@class=&#39;uitk-new-date-picker-month&#39;][1]//button[@data-day=&#39;29&#39;]]
2020-07-23 17:09:23.216 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button[data-stid=&#39;apply-date-picker&#39;] &gt; span]
2020-07-23 17:09:23.712 [main] INFO  Expedia - Scrolling to the page top in one-go
2020-07-23 17:09:24.048 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: preferred-class-input-trigger]
2020-07-23 17:09:24.634 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //a[@class=&#39;uitk-list-item&#39; and contains(text(),&#39;Economy&#39;)]]
2020-07-23 17:09:24.830 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: a[data-testid=&#39;travelers-field&#39;]]
2020-07-23 17:09:25.240 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;1&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: adult-input-0]
2020-07-23 17:09:25.304 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;adult-input-0&#39;]/following-sibling::button]
2020-07-23 17:09:25.472 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;2&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: adult-input-0]
2020-07-23 17:09:25.540 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;0&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: child-input-0]
2020-07-23 17:09:25.607 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;child-input-0&#39;]/following-sibling::button]
2020-07-23 17:09:25.847 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;1&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: child-input-0]
2020-07-23 17:09:25.914 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;0&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: infant-input-0]
2020-07-23 17:09:25.965 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;infant-input-0&#39;]/following-sibling::button]
2020-07-23 17:09:26.360 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;1&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: infant-input-0]
2020-07-23 17:09:26.437 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //button[contains(text(),&#39;Done&#39;)]]
2020-07-23 17:09:26.908 [main] INFO  Expedia - Capturing screenshot of the visible area and saving at path - E:\Testing\WebTesting\WebTesting\screenshots\23-Jul-20\05.08 PM\oneWayFlight_checkEconomyClassResultsDefaultDate\Dataset1_SS1.jpg
2020-07-23 17:09:28.413 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button[data-testid=&#39;submit-button&#39;]]
2020-07-23 17:09:43.180 [main] INFO  Expedia - The text &quot;Tue, 29 Dec&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: th.depart-date.selected]
2020-07-23 17:09:43.188 [main] INFO  Expedia - Highlighting the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: th.depart-date.selected]
2020-07-23 17:09:43.298 [main] INFO  Expedia - Capturing screenshot of the visible area and saving at path - E:\Testing\WebTesting\WebTesting\screenshots\23-Jul-20\05.08 PM\oneWayFlight_checkEconomyClassResultsDefaultDate\Dataset1_SS2.jpg
2020-07-23 17:09:43.900 [main] INFO  Expedia - oneWayFlight_checkEconomyClassResultsDefaultDate PASSED with parameters {Leaving from=Mumbai, Going to=Chennai, Departure Date=29/12/20, Travel Class=Economy, Adults=2.0, Children=1.0, Infants=1.0}
2020-07-23 17:09:43.903 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:09:43.904 [main] INFO  Expedia - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;ENDING TEST&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
2020-07-23 17:09:43.905 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:09:43.907 [main] INFO  Expedia - Deleting all the cookies
2020-07-23 17:09:57.603 [main] INFO  Expedia - Navigating to URL - https://www.expedia.co.in/
2020-07-23 17:10:02.192 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:10:02.194 [main] INFO  Expedia - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;STARTING TEST&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
2020-07-23 17:10:02.195 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:10:02.197 [main] INFO  Expedia - Starting Test execution for the test &quot;oneWayFlight_checkEconomyClassResultsDefaultDate&quot; with test data - {Leaving from=Bengaluru, Going to=Delhi, Departure Date=17/8/20, Travel Class=Economy, Adults=3.0, Children=1.0, Infants=2.0}
2020-07-23 17:10:02.677 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //span[text()=&#39;Flights&#39;]]
2020-07-23 17:10:05.273 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //span[text()=&#39;One-way&#39;]]
2020-07-23 17:10:06.514 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: [data-stid=&#39;location-field-leg1-origin-menu-trigger&#39;]]
2020-07-23 17:10:07.198 [main] INFO  Expedia - Sending text &quot;Bengaluru&quot; to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: location-field-leg1-origin]
2020-07-23 17:10:08.986 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //strong[contains(text(),&#39;Bengaluru&#39;)]]
2020-07-23 17:10:09.753 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: [data-stid=&#39;location-field-leg1-destination-menu-trigger&#39;]]
2020-07-23 17:10:10.446 [main] INFO  Expedia - Sending text &quot;Delhi&quot; to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: location-field-leg1-destination]
2020-07-23 17:10:12.128 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //strong[contains(text(),&#39;Delhi&#39;)]]
2020-07-23 17:10:12.400 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: d1-btn]
2020-07-23 17:10:13.227 [main] INFO  Expedia - Scrolling the page to bring the object &quot;[[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker]&quot; in the visible area
2020-07-23 17:10:14.637 [main] INFO  Expedia - The text &quot;July 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:10:14.675 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button.uitk-button.uitk-button-small.uitk-flex-item.uitk-button-paging:last-child]
2020-07-23 17:10:14.888 [main] INFO  Expedia - The text &quot;August 2020&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: div.uitk-new-date-picker-month:first-child h2]
2020-07-23 17:10:14.941 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //div[@class=&#39;uitk-new-date-picker-month&#39;][1]//button[@data-day=&#39;17&#39;]]
2020-07-23 17:10:15.088 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button[data-stid=&#39;apply-date-picker&#39;] &gt; span]
2020-07-23 17:10:15.244 [main] INFO  Expedia - Scrolling to the page top in one-go
2020-07-23 17:10:15.331 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: preferred-class-input-trigger]
2020-07-23 17:10:16.080 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //a[@class=&#39;uitk-list-item&#39; and contains(text(),&#39;Economy&#39;)]]
2020-07-23 17:10:16.246 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: a[data-testid=&#39;travelers-field&#39;]]
2020-07-23 17:10:17.200 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;1&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: adult-input-0]
2020-07-23 17:10:17.238 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;adult-input-0&#39;]/following-sibling::button]
2020-07-23 17:10:17.381 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;2&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: adult-input-0]
2020-07-23 17:10:17.420 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;adult-input-0&#39;]/following-sibling::button]
2020-07-23 17:10:17.493 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;3&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: adult-input-0]
2020-07-23 17:10:17.544 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;0&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: child-input-0]
2020-07-23 17:10:17.680 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;child-input-0&#39;]/following-sibling::button]
2020-07-23 17:10:17.928 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;1&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: child-input-0]
2020-07-23 17:10:17.983 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;0&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: infant-input-0]
2020-07-23 17:10:18.048 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;infant-input-0&#39;]/following-sibling::button]
2020-07-23 17:10:18.190 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;1&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: infant-input-0]
2020-07-23 17:10:18.240 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //input[@id=&#39;infant-input-0&#39;]/following-sibling::button]
2020-07-23 17:10:18.329 [main] INFO  Expedia - The value of the attribute(&quot;value&quot;) is &quot;2&quot; for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; id: infant-input-0]
2020-07-23 17:10:18.375 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; xpath: //button[contains(text(),&#39;Done&#39;)]]
2020-07-23 17:10:18.749 [main] INFO  Expedia - Capturing screenshot of the visible area and saving at path - E:\Testing\WebTesting\WebTesting\screenshots\23-Jul-20\05.08 PM\oneWayFlight_checkEconomyClassResultsDefaultDate\Dataset2_SS1.jpg
2020-07-23 17:10:19.549 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: button[data-testid=&#39;submit-button&#39;]]
2020-07-23 17:10:24.950 [main] INFO  Expedia - The text &quot;Mon, 17 Aug&quot; was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: th.depart-date.selected]
2020-07-23 17:10:24.954 [main] INFO  Expedia - Highlighting the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -&gt; css selector: th.depart-date.selected]
2020-07-23 17:10:25.147 [main] INFO  Expedia - Capturing screenshot of the visible area and saving at path - E:\Testing\WebTesting\WebTesting\screenshots\23-Jul-20\05.08 PM\oneWayFlight_checkEconomyClassResultsDefaultDate\Dataset2_SS2.jpg
2020-07-23 17:10:30.422 [main] INFO  Expedia - oneWayFlight_checkEconomyClassResultsDefaultDate PASSED with parameters {Leaving from=Bengaluru, Going to=Delhi, Departure Date=17/8/20, Travel Class=Economy, Adults=3.0, Children=1.0, Infants=2.0}
2020-07-23 17:10:30.423 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:10:30.423 [main] INFO  Expedia - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;ENDING TEST&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
2020-07-23 17:10:30.424 [main] INFO  Expedia - |******************************************************************************************************************|
2020-07-23 17:10:30.488 [main] INFO  Expedia - Closing all the windows/tabs opened by the WebDriver
2020-07-23 17:10:31.598 [main] INFO  Expedia - Suite execution completed

答案1

得分: 1

配置中有一个名为“ThresholdFilter”的部分,它“触发”发送电子邮件。如果收到级别为ERROR的日志消息,将导致发送电子邮件。

从问题中不清楚操作员(OP)想要什么替代触发器。
如果应该在收到级别为WARN的日志消息时发送电子邮件,只需重新配置过滤器为<ThresholdFilter level="warn" onMatch="NEUTRAL" onMismatch="DENY" />

如果其他事情应该触发发送电子邮件(无论日志消息的级别如何),那么您可以配置一个查找日志消息该方面的不同过滤器。Log4j2有许多内置过滤器,可以配置为触发发送电子邮件。如果这些都不符合您的要求,您可以创建自定义过滤器

因此,首先澄清自己希望触发的内容,然后配置或创建一个接受/对这种日志事件中立的过滤器,并拒绝不满足触发器要求的日志事件。

英文:

The configuration has a ThresholdFilter that "triggers" the sending of email. If a log message with level ERROR was received, that results in an email being sent.

It is not clear to me from the question what the OP wants as the replacement trigger.
If an email should be sent whenever a log message with level WARN was received, simply reconfigure the filter to &lt;ThresholdFilter level=&quot;warn&quot; onMatch=&quot;NEUTRAL&quot; onMismatch=&quot;DENY&quot; /&gt;.

If something else should trigger the sending of email (regardless of the level of the log message), then you can configure a different filter that looks for that aspect of the log message. Log4j2 has many built-in filters, and any of these can be configured to trigger sending email. If none of these meet your requirements, you can create a custom filter.

So, first clarify to yourself what should be the trigger, then configure or create a filter that accepts/is neutral to such log events and denies log events that do not meet the trigger requirement.

huangapple
  • 本文由 发表于 2020年7月23日 06:22:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63044021.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定