Link to home
Start Free TrialLog in
Avatar of _Esam
_Esam

asked on

How to configure log4j properly for custom struts action class?

Hi,

We have an struts/ejb web application.
I migrated the application from WAS 5.1 to WAS 6.1

Our struts has a custome action class defined in web.xml as:

<servlet>
            <servlet-name>action</servlet-name>
            <servlet-class>
            com.x.y.z.struts.ActionServlet</servlet-class>
            <init-param>
                  <param-name>config</param-name>
                  <param-value>/WEB-INF/struts-config.xml</param-value>
            </init-param>
            <init-param>
                  <param-name>debug</param-name>
                  <param-value>2</param-value>
            </init-param>
            <init-param>
                  <param-name>detail</param-name>
                  <param-value>2</param-value>
            </init-param>
            <init-param>
                  <param-name>validate</param-name>
                  <param-value>false</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
</servlet>


com.x.y.z.struts.ActionServlet servlet directly extends the struts Action class.


The web app uses both commons-logging-1.0.3.jar and log4j-1.2.8.jar (in the web-inf/lib folder).


We configured the log4j.xml file as:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false" threshold="null" xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="standardAppender" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="C:\\logs\\was\\application.log"/>
    <param name="DatePattern" value="yyyyMMdd"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="[%d{ISO8601}] %5p (%x) : %m%n"/>
    </layout>
  </appender>
    <appender name="synchAppender" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="C:\\logs\\was\\sas.log"/>
    <param name="DatePattern" value="yyyyMMdd"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="[%d{ISO8601}] %5p (%x) : %m%n"/>
    </layout>
  </appender>
  <logger name="application">
    <level value="debug"/>
    <appender-ref ref="standardAppender"/>
  </logger>
    <logger name="synch">
    <level value="trace"/>
    <appender-ref ref="synchAppender"/>
  </logger>
</log4j:configuration>



Now, the application does produce the log files and loggs the messages fine ...BUT ...
I get log4j warnings as:

[10/15/08 11:40:46:897 EDT] 0000001b SystemErr     R log4j:WARN No appenders could be found for logger (org.apache.struts.action.ActionServlet).
[10/15/08 11:40:46:897 EDT] 0000001b SystemErr     R log4j:WARN Please initialize the log4j system properly.

I can't seem to find what the problem here is; why is it giving the warning messages?

The log4j.xml and log4j.dtd files do get rightly placed under the web-inf/classes folder ...


Please let me know how to solve the warning messages for log4j?

Using RAD7/Java 5/ WAS 6.1

Thanks.
_Esam.
Avatar of sweetfa2
sweetfa2
Flag of Australia image

It obviously can't find the files.  Try moving them up one or two levels of directory.
Avatar of _Esam
_Esam

ASKER

It does find the files as I already mentioned:
>>
Now, the application does produce the log files and loggs the messages fine ...BUT ...
I get log4j warnings as:

[10/15/08 11:40:46:897 EDT] 0000001b SystemErr     R log4j:WARN No appenders could be found for logger (org.apache.struts.action.ActionServlet).
[10/15/08 11:40:46:897 EDT] 0000001b SystemErr     R log4j:WARN Please initialize the log4j system properly.
<<

It works fine on WAS 5.1 but does this on WAS 6.1.
Obviously something is different here.

Thax.
_Esam
You have not defined the logger org.apache.struts.action.ActionServlet. You need to define it on log4j.xml

On WAS5.1, It appears to me that it might be using different log4j configration file
ASKER CERTIFIED SOLUTION
Avatar of _Esam
_Esam

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial