log4jmaven-3websphere-7maven-ear-plugin

Log4j Issue with Skinny WAR: Logs are merged into single log file instead of writing into separate web applications log files


I am using Websphere7 to deploy EAR file. EAR file contains two different application war files like App1, App2.

I am building my application EAR file using maven-ear-plugin as skinny war.

.
 |-- META-INF
 |   `-- application.xml
 |-- lib
 |    -- jar1
 |    -- jar2
 |    -- jar3
 |    -- log4j.jar
 |-- App1-1.0.0.war
 |     -- /WEB-INF/classes/App1-log4j.xml     |     
 `-- App2-1.0.0.war
 |     -- /WEB-INF/classes/App2-log4j.xml

Web.xml Configuration for different Wars

App1-1.0.0.war: Web.xml

<context-param>
            <param-name>log4jExposeWebAppRoot</param-name>
            <param-value>false</param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/App1-log4j.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

App2-1.0.0.war: Web.xml

 <context-param>
                <param-name>log4jExposeWebAppRoot</param-name>
                <param-value>false</param-value>
        </context-param>

        <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>/WEB-INF/classes/App2-log4j.xml</param-value>
        </context-param>

        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener>

I am facing issue related to logging. Two different log files (app1.log and app2.log) are created properly on application start up. But logs for different applications are going to single log file.

Am I missing anything? Any suggestions?


Solution

  • Finally, I have got the solution for this problem. To get the answer refer below links.

    During implementing this solution, I have observed that static Logger variable in all classes was causing the log merging issue. Here is the good explanation regarding this issue. After reading this, I had to convert all static Logger to class level instance variable.

    From

    private static final Logger LOGGER = Logger.getLogger(MyApp.class);

    To

    private final Logger LOGGER = Logger.getLogger(MyApp.class);

    After following above changes, logging framework started working fine for me. Now, I can see my all log files contains web app specific logs.

    If you want to get detailed analysis on this issue. You can refer this post.