<html><body bgcolor="#FFFFFF"><div>Hi <span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); font-family: 'Courier New'; ">Sotirios,</span></div><div><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); font-family: 'Courier New'; "><br></span></div><div>In your servlet code you are logging at debug level. In your junit test case you are logging at error level. The log back configuration create a logger at info level. This explains why the error log message gets to the log and not the debug log message gets to the log.<br><br></div><div>Happy to help,<br>Brett</div><div><br>On 12/03/2012, at 9:59 AM, "Sotiris Delimanolis" <<a href="mailto:sotodel_89@hotmail.com">sotodel_89@hotmail.com</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div><div dir="ltr">
<font style="" face="Courier New">Hi,</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"><br></font><font style="" face="Courier New">I'm developing a Java web application through Tomcat with Java servlets. In my constructor for one servlet I call the following code:</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"><br></font><font style="" face="Courier New">public MyServlet () {</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"> // Initialise the logger</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"> logger = (Logger)LoggerFactory.getLogger("application");</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"> logger.debug("Starting application");</font><font style="" face="Courier New"><br></font><font style="" face="Courier New">}</font><font style="" face="Courier New"><br></font><font style="" face="Courier New"><br>My logback.xml configuration file is the following:<br><br><?xml version="1.0" encoding="UTF-8"?><br><br><configuration debug="true"><br><br> <appender name="FILE"<br> class="ch.qos.logback.core.FileAppender"><br> <file>application.log</file><br> <append>true</append><br><br> <encoder><br> <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n<br> </pattern><br> </encoder><br> </appender><br><br> <logger name="application" level="INFO"><br> <appender-ref ref="FILE" /><br> </logger><br></configuration><br><br>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.<br><br>Within the same project, I try to test the Logger. In a junit test I have the following:<br><br>public class TestLogging extends TestCase {<br> public void testApplicationLogger() {<br> // Initialise the logger<br> Logger logger = (Logger)LoggerFactory.getLogger("application");<br> logger.error("Starting application");<br> }<br>}<br><br>This generates a file, a outputs "201 [main] ERROR application - Starting application"<br><br>Why can't I get the logger to output anything from the servlet?<br><br>Regards,<br></font><font style="" face="Courier New">Sotirios</font> </div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Logback-user mailing list</span><br><span><a href="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a></span><br><span><a href="http://mailman.qos.ch/mailman/listinfo/logback-user">http://mailman.qos.ch/mailman/listinfo/logback-user</a></span></div></blockquote></body></html>