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")
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. ',' '.'