Log4j2 configuration file not recognized

I am trying to configure log4j2 in my Geb structure. For life, I cannot figure out how to do this. I have a log4j2.xml file (not log4j.xml) with a "Selenium" logger. In DefaultPage, I am trying to get a Logger named Selenium from a configuration file LogManager.getLogger("Selenium").

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss,SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
      <Logger name="Selenium" level="TRACE">
          <AppenderRef ref="Console"/>
      </Logger>
    <Root level="TRACE">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

DefaultPage.groovy

class DefaultPage extends geb.Page {
    static content = {
        pageId(wait: true) { $("meta", name: "pageId").getAttribute("content") }
        pageHeading(wait: true) { $("meta", name: "heading").getAttribute("content") }
    }

    static final Logger logger = LogManager.getLogger("Selenium")

    /**
     * Uses jquery to create a mouseover on an element
     * @param element The jquery element created in the page object.
     */
    static def mouseOver(element) {
        logger.error("Hovering over ${element}")
        element.jquery.mouseover()
    }
}

The test is executed and the output is written to STDERR, which is expected because I have logger.error. However, it does not support the date format. In addition, I have other classes calling this registrar with .info, and they are not visible in STDOUT. When I debug the logger level, it is ERROR, not TRACE.

Here is my file structure:

functional
|
 --src
   |
   |--test
      |
      |--groovy
      |     |
      |     |--com.x.functional
      |         |
      |         |--pages
      |              |
      |              |--DefaultPage.groovy
      |              |--Other classes that want to use log4j2.
      |
      |--resources
             |
             |--log4j2.xml

Thanks.

log4j log4j2. = TRACE. ',' '.'

+4
2

Log4J2 log4j2.xml . , (. ), log4j.xml . ( log4j2 config: http://logging.apache.org/log4j/2.x/faq.html#config_location)

, , ERROR StdErr.

, , . - log4j2.xml . log4j2, <Configuration status="trace"> , .

+3

, , - , .

TIMBERings, . eclipse, "" Java.

<Configuration status="trace">, <Configuration>.

"." "," ss SSS %d{HH:mm:ss.SSS} ( ).

.

+1

Source: https://habr.com/ru/post/1529499/


All Articles