I am using SL4j and Logback for a web application hosted in Tomcat. I use Spring and Maven (no profiles). Integration testing is performed using the Surefire plugin:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.12</version> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> <configuration>...</configuration> </execution> <execution> <id>verify</id> <goals> <goal>verify</goal> </goals> </execution> </executions> </plugin>
Inside the logback configuration, I have a file based application:
<appender name="A2" class="ch.qos.logback.core.FileAppender"> <file>myapp.log</file> ...
The log files for the integration test and webapp were separated by coincidence: for the integration test, this was the root of my project, for webapp it was the Eclipse directory. Thus, I presented the location of the log file in the log configuration:
<insertFromJNDI env-entry-name="java:comp/bla/logDir" as="logDir" /> <if condition='!isDefined("logDir")'> <then> <property name="logDir" value="${catalina.home}/logs/" /> </then> </if>
Now if combined with isDefined works, I forgot Janino on the way to classes (thanks Ceki). Both test log output and web application log output in the same log file. So my question is:
How can I separate log files for a web application for integration testing? I found the link, but I would prefer a solution with only customization. I really would like to add Maven properties.
Update My problem has been resolved. First log configuration:
<configuration scan="true" debug="true"> <insertFromJNDI env-entry-name="java:comp/bla/logDir" as="logDir" /> <if condition='!isDefined("logDir")'> <then> <if condition='isDefined("catalina.home")'> <then> <property name="logDir" value="${catalina.home}/logs/" /> </then> <else> <property name="logDir" value="./" /> </else> </if> </then> </if>
The appender file property looks like this:
<file>${logDir}/myapp.log</file>
In this solution, it is strangely strange:
- logback considers the property to be undefined when it is empty. So I had to use
"./" instead of "" (empty string). isDefined("catalina.home") results true only when launched in Tomcat (OS - Windows). I don't know why "catalina.home" is defined anyway, I have an environment variable called "CATALINA_HOME", but it flips that TomCat sets "catalina.home" at startup.
I would still like to insert Maven var in the logback configuration (project root), but I'm afraid that I will have to live with the solution above.
spring maven logback janino
Chrlipp
source share