Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:18:47+00:00 2026-06-04T20:18:47+00:00

I am using SL4j and Logback for a web application hosted in Tomcat. I

  • 0

I am using SL4j and Logback for a web application hosted in Tomcat. I use Spring and Maven (no profiles). Integration testing is done with 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 appender:

<appender name="A2" class="ch.qos.logback.core.FileAppender">
    <file>myapp.log</file>
    ...

The log files for integration test and the webapp have been seperated by coincidence: for the integration test it was the root of my project, for the webapp it was the Eclipse directory. So I introduced a log file location inside the logback config:

<insertFromJNDI env-entry-name="java:comp/bla/logDir" as="logDir" />
<if condition='!isDefined("logDir")'>
    <then>
        <property name="logDir" value="${catalina.home}/logs/" />
    </then>
</if>

The if in combination with isDefined works now, I forgot Janino on the classpath (thanks to Ceki). Both integration test log output and web application log output in the same log file. So my question:

How could I seperate the log files for integration test web application?
I found this link, but I would prefer a solution with configuration only. I really would love to insert Maven properties.

Update
My problem is solved. First the logback config:

<configuration scan="true" debug="true">
    <!-- used for the production webapp -->
    <insertFromJNDI env-entry-name="java:comp/bla/logDir" as="logDir" />
    <if condition='!isDefined("logDir")'>
        <then>
            <if condition='isDefined("catalina.home")'>
                <then>
                    <!-- used for the development webapp -->
                    <property name="logDir" value="${catalina.home}/logs/" />
                </then>
                <else>
                    <!-- used for the integration test -->
                    <property name="logDir" value="./" />
                </else>
            </if>
        </then>
    </if>

The appender file property looks like:

    <file>${logDir}/myapp.log</file>

2 things are strange in this solution:

  1. logback thinks that a property is undefined when it is empty. So I had to use "./" instead of "" (empty string).
  2. isDefined("catalina.home") results true only when started in Tomcat (OS is Windows). Don’t know why “catalina.home” is defined anyway, I have a environment var called “CATALINA_HOME”, but it seams that TomCat is setting “catalina.home” on start.

I still would like to insert a Maven var into the logback config (the project root), but I am afraid I have to live with the solution above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:18:48+00:00Added an answer on June 4, 2026 at 8:18 pm

    Conditional configuration (if statement) requires Janino. Is Janino available on your class path? Have you set the debug attribute to true as follows?

    <configuration debug="true">...</configuration>
    

    Setting the debug attribute to true will print logback’s internal status messages on the console which can be very useful in tracking down logback configuration problems.

    As for the separation question, have you considered separation by hostname? Logback automatically defines HOSTNAME as a variable. So the following would define two separate logging settings based on productionHost and other hosts.

    <if condition='property("HOSTNAME").contains("productionHost")'>
        <then>...</then>
        <else>config for test</else>
    </if>
    

    Actually, I don’t see why the separation according to the definition of ‘logDir’ is insufficient for achieving separation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Android TelephonyManager an application can obtain the state of data activity over the
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using Java, how can I extract all the links from a given web page?
Using Spring MVC, do interceptors only intercept defined controller mappings or can they also
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using JDeveloper , I started developing a set of web pages for a project
Using Rails 3 and ActiveModel, I am unable to use the self. syntax to
I have an application which use java.util logging and libraries used by this application
Using Server.Transfer to show a page that informs the user that the web site
Using Firebug I have extracted all the links of a web page using: var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.