I'm building a web service using jax-rs and wanted to log some stuff when urls are called. I found about log4j 2 and decided to use it. I dont know why but it works when I do some tests
Response response = target("user/v1/"+alfred.getPseudo()).request().get();
assertTrue(response.getStatus() < 300);
This will put the log String in logs/logs.log (I love logs). Yet, when I deploy (with glassfish 4.1.1), it doesn't write a single char in the file when I call the same URL.
Here's my log4j2.xml
(located in src/main/resources) :
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<File name="File" fileName="logs/logs.log">
<PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS}[%t] %c{1} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
My web.xml
is empty :
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
I have the lo4j-api and log4j-core, both 2.5, in my pom.xml.
Finally, here's the code :
private final static Logger logger = LogManager.getLogger(MyClass.class);
on which I just call logger.info(String)
and logger.error(String)
.
What am I doing wrong, and what should I do to create logs when deploying ?
Thanks.
EDIT : Perhaps this will help. I previously had
<File name="File" fileName="logs/logs.log" bufferedIO="false">
When I was testing, I had a warning "Hey, you set bufferedIO to false but the default buffer size is 8192, wtf". And this warning was being shown when i was calling the urls during real deployment. I guess that means my configuration was detected when deploying aswell.