Solved

How to configure log4j properly for custom struts action class?

Posted on 2008-10-15
4
2,094 Views
Last Modified: 2013-11-24
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.
0
Comment
Question by:_Esam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22725109
It obviously can't find the files.  Try moving them up one or two levels of directory.
0
 

Author Comment

by:_Esam
ID: 22726115
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
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 22728210
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
0
 

Accepted Solution

by:
_Esam earned 0 total points
ID: 24291395
I have not found any suitable answer to the question.
I will request to have this question deleted.

Thanks.
_Esam
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question