I'm trying to get log4j2 setup in my Geb framework. For the life of me I can't figure out how to put this together. I have a log4j2.xml (not log4j.xml) file setup with the logger "Selenium". In DefaultPage I try to get the Logger with the name Selenium from the config 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 executes and output is written to STDERR, which is expected because I have logger.error. However, it doesn't hold format for the date. Additionally I have other classes calling this logger with .info and those are not seen in STDOUT. When I debug the level of the logger is ERROR, not TRACE.
Here's my file structure:
functional
|
--src
|
|--test
|
|--groovy
| |
| |--com.x.functional
| |
| |--pages
| |
| |--DefaultPage.groovy
| |--Other classes that want to use log4j2.
|
|--resources
|
|--log4j2.xml
Thank you.
EDIT Changing log4j to log4j2. Adding Configuration status = TRACE. Modified date format for milliseconds with ',' instead of '.'
%d{HH:mm:ss,SSS}
(note the comma instead of.
for millisecs) – Jeanicejeanie