[logback-user] Using FileAppender to log within servlet not producing output
Brett Walker
brett.walker at geometryit.com
Mon Mar 12 01:54:06 CET 2012
Sotirios,
It sounds like you have solved you initial problem. Is this the case?
Brett
On 12/03/2012, at 11:46 AM, "Sotiris Delimanolis" <sotodel_89 at hotmail.com<mailto:sotodel_89 at hotmail.com>> wrote:
Thanks for the answer, but I don't think that was it. That was just sloppy copy-pasting. I tried with both levels.
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.
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.
Sotirios
________________________________
From: <mailto:brett.walker at geometryit.com> brett.walker at geometryit.com<mailto:brett.walker at geometryit.com>
To: <mailto:logback-user at qos.ch> logback-user at qos.ch<mailto:logback-user at qos.ch>
Date: Mon, 12 Mar 2012 11:41:28 +1100
Subject: Re: [logback-user] Using FileAppender to log within servlet not producing output
Hi Sotirios,
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.
Happy to help,
Brett
On 12/03/2012, at 9:59 AM, "Sotiris Delimanolis" <<mailto:sotodel_89 at hotmail.com>sotodel_89 at hotmail.com<mailto:sotodel_89 at hotmail.com>> wrote:
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
_______________________________________________
Logback-user mailing list
<mailto:Logback-user at qos.ch>Logback-user at qos.ch<mailto:Logback-user at qos.ch>
<http://mailman.qos.ch/mailman/listinfo/logback-user>http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________ Logback-user mailing list Logback-user at qos.ch<mailto:Logback-user at qos.ch> <http://mailman.qos.ch/mailman/listinfo/logback-user> http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________
Logback-user mailing list
Logback-user at qos.ch<mailto:Logback-user at qos.ch>
http://mailman.qos.ch/mailman/listinfo/logback-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20120312/6d52b95e/attachment.html>
More information about the Logback-user
mailing list