If the webapps are configured to use child-first, or parent-last, classloading and log4j.jar is in WEB-INF/lib and log4j.xml is in WEB-INF/classes (or you specify the config path yourself using the Spring configuration utility), then logging should be separated.

Shared libraries located outside of WEB-INF/lib (such as in APP-INF/lib under Weblogic) can be problematic since they'll have dependency on Log4j and won't be able to reference it under each webapp's WEB-INF/lib.

The other option is a repository selector, but that entails some more complication.  There's documentation for it in the logging-log4j wiki [1].  You may still end up with problems when shared libraries log using static loggers, though, since they will be tied to the configuration of the first app that accesses them.

[1] http://wiki.apache.org/logging-log4j/AppContainerLogging


Jake

On Tue, 21 Jun 2011 18:03:20 +0300
 Melih U. Ünsal <melihun...@gmail.com> wrote:
My ear project consists of two war applications. i want to create logs
individually for every war. i mean every war projects must create its own
logs. But, because of they run in the same jvm, i am not sure whether it is
possible or not.
how can i handle this issue?

By the way, the war applications are spring projects.

i created two log4j config files (log4j_app1.xml and log4j_app2.xml) and
instantiated them in the applicationcontexts but it did not solve the
problem.

WAR_APP1 applcaitoncontext.xml :

<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"
value="org.springframework.util.Log4jConfigurer" />
    <property name="targetMethod" value="initLogging" />
    <property name="arguments">
    <list>
        <value>/config/log4j_app1.xml</value>
    </list>
    </property>
</bean>


WAR_APP2 applcaitoncontext.xml :

<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"
value="org.springframework.util.Log4jConfigurer" />
    <property name="targetMethod" value="initLogging" />
    <property name="arguments">
    <list>
        <value>/config/log4j_app2.xml</value>
    </list>
    </property>
</bean>


log4j_app1.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd
">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

    <appender name="appender"
class="org.apache.log4j.DailyRollingFileAppender">
        <param name="DatePattern" value="'.'yyyy-MM-dd"/>
        <param name="File" value="/logs/app1/app1.log"/>
        <param name="Append" value="true"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
        </layout>
    </appender>

    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d  - %5p %c{1} - %m%n"/>
        </layout>
    </appender>

    <root>

        <priority value="info"/>
        <appender-ref ref="appender"/>
        <appender-ref ref="console"/>

    </root>

</log4j:configuration>
log4j_app2.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd
">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>

    <appender name="appender_ui"
class="org.apache.log4j.DailyRollingFileAppender">
        <param name="DatePattern" value="'.'yyyy-MM-dd"/>
        <param name="File" value="/logs/app2/app2.log"/>
        <param name="Append" value="true"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %p - %m%n"/>
        </layout>
    </appender>

    <appender name="console_ui" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d  - %5p %c{1} - %m%n"/>
        </layout>
    </appender>

    <root>

        <priority value="info"/>
        <appender-ref ref="appender_ui"/>
        <appender-ref ref="console_ui"/>

    </root>

</log4j:configuration>


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to