[logback-user] Using FileAppender to log within servlet not producing output
Sotiris Delimanolis
sotodel_89 at hotmail.com
Sun Mar 11 23:59:43 CET 2012
Hi,
I'm developing a Java web application through Tomcat with Java servlets. In my constructor for one servlet I call the following code:
public MyServlet () {
// Initialise the logger
logger = (Logger)LoggerFactory.getLogger("application");
logger.debug("Starting application");
}
My logback.xml configuration file is the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<appender name="FILE"
class="ch.qos.logback.core.FileAppender">
<file>application.log</file>
<append>true</append>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="application" level="INFO">
<appender-ref ref="FILE" />
</logger>
</configuration>
When I launch the web app, the constructor is called by Tomcat, which should run the above code, but no file ("application.log") is created and no output is done anywhere.
Within the same project, I try to test the Logger. In a junit test I have the following:
public class TestLogging extends TestCase {
public void testApplicationLogger() {
// Initialise the logger
Logger logger = (Logger)LoggerFactory.getLogger("application");
logger.error("Starting application");
}
}
This generates a file, a outputs "201 [main] ERROR application - Starting application"
Why can't I get the logger to output anything from the servlet?
Regards,
Sotirios
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120311/c5940c26/attachment.html>
More information about the Logback-user
mailing list