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: [email protected]
To: [email protected]
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" <[email protected]> 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
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________
Logback-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user
_______________________________________________
Logback-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user