即使不存在错误,也会收到包含执行日志的电子邮件

Get email with execution log even when no error exists

我的要求:

  1. 如果在执行过程中遇到错误,我需要发送一封包含错误日志以及日志级别 >= INFO 的先前日志的电子邮件。 我目前的配置满足这个要求。
  2. 如果执行中没有错误,我需要电子邮件在执行期间记录所有消息,日志级别 >=INFO。 这里需要帮助。我目前的配置不满足这个要求

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

<Configuration status="INFO">
    <Properties>
        <Property name="standardPattern">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %m%n</Property>
        <Property name="mailSubject">Execution Log</Property>
        <Property name="recipients">xxxx@gmail.com</Property>
        <Property name="sender">xx@gmail.com</Property>
        <Property name="host">smtp.gmail.com</Property>
        <Property name="port">587</Property>
        <Property name="username">xx@gmail.com</Property>
        <Property name="protocol">smtp</Property>
        <Property name="password">secret</Property>
        <Property name="bufferSize">512</Property>
    </Properties>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="${standardPattern}" />
        </Console>
        <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}" />
            <ThresholdFilter level="error" onMatch="NEUTRAL"
                onMismatch="DENY" />
        </SMTP>
        <Async name="asyncMail">
            <AppenderRef ref="mailLog" />
        </Async>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console" />
        </Root>
        <Logger name="test" level="info" additivity="false">
            <AppenderRef ref="Console" />
            <AppenderRef ref="asyncMail"/>
        </Logger>
    </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");

不出所料,我收到了 2 封电子邮件,内容如下:

第一封电子邮件(跟踪和调试被忽略,因为记录器的日志级别设置为 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

第二封邮件:

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 所说,我必须决定电子邮件的触发器,以防在执行过程中没有错误。我分析了我的日志并检查了每当执行完成时没有任何 issues/errors,我发送日志消息 Suite execution completed。因此,牢记这一点,我最终使用 SMTP 附加程序的复合过滤器,如下所示:

<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>

解释:

以下是执行完成后没有任何错误发送给我的:

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 "chrome" 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 - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>>>>>>>>>>>>>>>>>STARTING TEST<<<<<<<<<<<<<<!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
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 "oneWayFlight_checkEconomyClassResultsDefaultDate" 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)] -> xpath: //span[text()='Flights']]
2020-07-23 17:09:08.131 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //span[text()='One-way']]
2020-07-23 17:09:12.832 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: [data-stid='location-field-leg1-origin-menu-trigger']]
2020-07-23 17:09:13.663 [main] INFO  Expedia - Sending text "Mumbai" to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: location-field-leg1-origin]
2020-07-23 17:09:14.981 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //strong[contains(text(),'Mumbai')]]
2020-07-23 17:09:15.377 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: [data-stid='location-field-leg1-destination-menu-trigger']]
2020-07-23 17:09:15.652 [main] INFO  Expedia - Sending text "Chennai" to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: location-field-leg1-destination]
2020-07-23 17:09:18.038 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //strong[contains(text(),'Chennai')]]
2020-07-23 17:09:18.758 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: d1-btn]
2020-07-23 17:09:19.151 [main] INFO  Expedia - Scrolling the page to bring the object "[[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: div.uitk-new-date-picker]" in the visible area
2020-07-23 17:09:20.778 [main] INFO  Expedia - The text "July 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> 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 "August 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> 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 "September 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> 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 "October 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> 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 "November 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> 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 "December 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> xpath: //div[@class='uitk-new-date-picker-month'][1]//button[@data-day='29']]
2020-07-23 17:09:23.216 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: button[data-stid='apply-date-picker'] > 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)] -> id: preferred-class-input-trigger]
2020-07-23 17:09:24.634 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //a[@class='uitk-list-item' and contains(text(),'Economy')]]
2020-07-23 17:09:24.830 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: a[data-testid='travelers-field']]
2020-07-23 17:09:25.240 [main] INFO  Expedia - The value of the attribute("value") is "1" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: adult-input-0]
2020-07-23 17:09:25.304 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='adult-input-0']/following-sibling::button]
2020-07-23 17:09:25.472 [main] INFO  Expedia - The value of the attribute("value") is "2" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: adult-input-0]
2020-07-23 17:09:25.540 [main] INFO  Expedia - The value of the attribute("value") is "0" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: child-input-0]
2020-07-23 17:09:25.607 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='child-input-0']/following-sibling::button]
2020-07-23 17:09:25.847 [main] INFO  Expedia - The value of the attribute("value") is "1" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: child-input-0]
2020-07-23 17:09:25.914 [main] INFO  Expedia - The value of the attribute("value") is "0" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: infant-input-0]
2020-07-23 17:09:25.965 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='infant-input-0']/following-sibling::button]
2020-07-23 17:09:26.360 [main] INFO  Expedia - The value of the attribute("value") is "1" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: infant-input-0]
2020-07-23 17:09:26.437 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //button[contains(text(),'Done')]]
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-Jul-20.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)] -> css selector: button[data-testid='submit-button']]
2020-07-23 17:09:43.180 [main] INFO  Expedia - The text "Tue, 29 Dec" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: th.depart-date.selected]
2020-07-23 17:09:43.188 [main] INFO  Expedia - Highlighting the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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-Jul-20.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 - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>>>>>>>>>>>>>>>>>ENDING TEST<<<<<<<<<<<<<<<<!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
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 - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>>>>>>>>>>>>>>>>>STARTING TEST<<<<<<<<<<<<<<!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
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 "oneWayFlight_checkEconomyClassResultsDefaultDate" 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)] -> xpath: //span[text()='Flights']]
2020-07-23 17:10:05.273 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //span[text()='One-way']]
2020-07-23 17:10:06.514 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: [data-stid='location-field-leg1-origin-menu-trigger']]
2020-07-23 17:10:07.198 [main] INFO  Expedia - Sending text "Bengaluru" to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: location-field-leg1-origin]
2020-07-23 17:10:08.986 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //strong[contains(text(),'Bengaluru')]]
2020-07-23 17:10:09.753 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: [data-stid='location-field-leg1-destination-menu-trigger']]
2020-07-23 17:10:10.446 [main] INFO  Expedia - Sending text "Delhi" to the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: location-field-leg1-destination]
2020-07-23 17:10:12.128 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //strong[contains(text(),'Delhi')]]
2020-07-23 17:10:12.400 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: d1-btn]
2020-07-23 17:10:13.227 [main] INFO  Expedia - Scrolling the page to bring the object "[[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: div.uitk-new-date-picker]" in the visible area
2020-07-23 17:10:14.637 [main] INFO  Expedia - The text "July 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> 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 "August 2020" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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)] -> xpath: //div[@class='uitk-new-date-picker-month'][1]//button[@data-day='17']]
2020-07-23 17:10:15.088 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: button[data-stid='apply-date-picker'] > 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)] -> id: preferred-class-input-trigger]
2020-07-23 17:10:16.080 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //a[@class='uitk-list-item' and contains(text(),'Economy')]]
2020-07-23 17:10:16.246 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: a[data-testid='travelers-field']]
2020-07-23 17:10:17.200 [main] INFO  Expedia - The value of the attribute("value") is "1" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: adult-input-0]
2020-07-23 17:10:17.238 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='adult-input-0']/following-sibling::button]
2020-07-23 17:10:17.381 [main] INFO  Expedia - The value of the attribute("value") is "2" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: adult-input-0]
2020-07-23 17:10:17.420 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='adult-input-0']/following-sibling::button]
2020-07-23 17:10:17.493 [main] INFO  Expedia - The value of the attribute("value") is "3" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: adult-input-0]
2020-07-23 17:10:17.544 [main] INFO  Expedia - The value of the attribute("value") is "0" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: child-input-0]
2020-07-23 17:10:17.680 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='child-input-0']/following-sibling::button]
2020-07-23 17:10:17.928 [main] INFO  Expedia - The value of the attribute("value") is "1" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: child-input-0]
2020-07-23 17:10:17.983 [main] INFO  Expedia - The value of the attribute("value") is "0" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: infant-input-0]
2020-07-23 17:10:18.048 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='infant-input-0']/following-sibling::button]
2020-07-23 17:10:18.190 [main] INFO  Expedia - The value of the attribute("value") is "1" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: infant-input-0]
2020-07-23 17:10:18.240 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //input[@id='infant-input-0']/following-sibling::button]
2020-07-23 17:10:18.329 [main] INFO  Expedia - The value of the attribute("value") is "2" for the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> id: infant-input-0]
2020-07-23 17:10:18.375 [main] INFO  Expedia - Clicking on the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> xpath: //button[contains(text(),'Done')]]
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-Jul-20.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)] -> css selector: button[data-testid='submit-button']]
2020-07-23 17:10:24.950 [main] INFO  Expedia - The text "Mon, 17 Aug" was fetched from the object [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> css selector: th.depart-date.selected]
2020-07-23 17:10:24.954 [main] INFO  Expedia - Highlighting the object - [[ChromeDriver: chrome on WINDOWS (e6d90b3b9c443edc5ce4b7226f26c405)] -> 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-Jul-20.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 - |!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>>>>>>>>>>>>>>>>>ENDING TEST<<<<<<<<<<<<<<<<!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!|
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

配置有一个 ThresholdFilter 可以“触发”发送电子邮件。如果收到级别为 ERROR 的日志消息,则会导致发送电子邮件。

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

如果其他东西应该触发电子邮件的发送(无论日志消息的级别如何),那么您可以配置一个不同的过滤器来查找日志消息的那个方面。 Log4j2有很多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.

所以,首先要明确自己应该触发什么,然后配置或创建一个过滤器,accepts/is对此类日志事件保持中立,并拒绝不符合触发要求的日志事件。