Search code examples
javalog4jweblogicear

Log file not produced until WebLogic is restarted


I'm working on the development of an application that is deployed on WebLogic 10.3. It is packaged as an EAR and includes one module. The application works fine by itself but I am faced with issue related to logging.

I am using Log4j. The library is included in the EAR file and log4j.xml is placed under JAR module. So the config location is the following:

A.ear/B.jar/log4j.xml

Log4j config is following:

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

<appender name="CA" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{dd-MMM-yyyy-HH:mm:ss} %p %C{1} - %m%n" />
    </layout>
</appender>


<appender name="DRFA" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="file"
        value="servers/AdminServer/logs/EJB.log" />
    <param name="Append" value="true" />
    <param name="DatePattern" value="'-'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{dd-MMM-yyyy-HH:mm:ss} %p %C{1} - %m%n" />
    </layout>
</appender>


<logger name="com.companyname.ejb" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="DRFA" />
    <appender-ref ref="CA" />
</logger>

<logger name="com.companyname.results" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="DRFA" />
    <appender-ref ref="CA" />
</logger>

<logger name="com.companyname.marketdata" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="DRFA" />
    <appender-ref ref="CA" />
</logger>


<root>
    <level value="DEBUG" />
    <appender-ref ref="CA" />
</root>

When I build and deploy EAR (using Maven and customized WebLogic plugin) and call application no log file appears. But if I restart WebLogic everything is fine.

WebLogic is running under Windows 7 in domain mode with single node.

I'd like to know if there is some way to make the log appear without weblogic restart (since it can cause issues on production environment)?

Update: Also I'd like to know what is the reason of such behavior (i.e. why the log file is not created right after application deployment)? Is this an issue with Weblogic, log4j or with their coupling? I've tried to find the answer in the Oracle documentation, but no luck for now.


Solution

  • I didn't found any quick configuration solution, so code change was required.

    I've added Weblogic Application Lifecycle listener as suggested here. Its postStart() method initializes log4j explicitly through DOMConfigurator and now logs appear right after application deployment.

    The are few alternatives how configuration can be initialized. One of them was mentioned in eis' post and another here. But I've choose listener in order to keep single module in EAR and in order to avoid issues with singleton EJB on cluster environment (i.e. I am not sure if Weblogic will create singleton on each node or just one instance per cluster).

    Also in order to prevent environment changes for local and dev environment, I am using internal log4j.xml (i.e. placed within ear file) there.

    For stage and prod - external config file is specified (in Maven profile).

    External file is monitored by log4j so changes will be automatically applied without any redeployments or restarts.