<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Thanks for the answer, but I don't think that was it. That was just sloppy copy-pasting. I tried with both levels. <br><br>What I changed was the path to the file. I think that because it was a relative path, it wrote (or didn't) to some random place. I changed the path to "${user.dir}/logs/application.log" and it now writes to my eclipse folder under ../logs.application.log.<br><br>The test case was not run within the web-application so it's path was in the project folder. That's why it wrote to the project folder.<br><br>Sotirios<br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: brett.walker@geometryit.com<br>To: logback-user@qos.ch<br>Date: Mon, 12 Mar 2012 11:41:28 +1100<br>Subject: Re: [logback-user] Using FileAppender to log within servlet not producing output<br><br><div>Hi <span class="ecxApple-style-span" style="font-family:'Courier New'">Sotirios,</span></div><div><span class="ecxApple-style-span" style="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><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><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" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a></span></div></blockquote><br>_______________________________________________
Logback-user mailing list
Logback-user@qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-user</div> </div></body>
</html>