On Fri, 5 Dec 2003, Pedro Salgado wrote:

>
> Do you have the log4j jar on the WEB-INF/lib?
> Do you have the log4j.properties on the WEB-INF/classes?
>
> You have:
> String str = new String(LogonAction.class.getName());
> Logger logger = Logger.getLogger(str);
>
> Shouldn't it be:
> Logger logger = Logger.getLogger(LogonAction.class);

Not sure if this was mentioned, but you should configure your app to use
commons-logging and then specify in its configuration to use Log4j.  That
way you can swap out logging implementations by simple configuration and
library addtions/removal (no recompile necessary).

What I do it this:
under /WEB-INF/classes
 - commons-logging.properties

#
# Directly selects log4j logging implementation class.
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory

# Maps to a Log4J category (uses log4j.properties)
#  note: org.apache.log4j.Category is deprecated in favor of
org.apache.log4j.Logger
#  and requests for a Category object will return a Logger object.
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog


 - log4j.properties

# Set the root logger level to DEBUG and its only appender to rolling

log4j.rootLogger=WARN, rolling, stdout

# Set the logger level for everything under "org.apache" to WARN
log4j.logger.org.apache=WARN
log4j.logger.com.company.framework.common.util.ApplicationConfig=WARN

# Set the logger level for "org.apache.commons.validator.ValidatorUtil" to
# FATAL because we know that errors will be generated here that we want to
# ignore (due to the fact that it is unknown whether a consumer is
personal
# or business and the validation.xml file is not set up to accomodate the
# differences)

log4j.logger.org.apache.commons.validator.ValidatorUtil=FATAL
log4j.logger.org.apache.log4j.TextLogger=INFO


# Configure the stdout appender to be a ConsoleAppender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender

# Configure the stdout appender to use the PatternLayout
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Configure the conversion pattern for the stdout appender
log4j.appender.stdout.layout.ConversionPattern=%d - %p %c - %m%n

# Configure the rolling appender to be a RollingFileAppender
log4j.appender.rolling=org.apache.log4j.RollingFileAppender

# Configure the name of the log file for the rolling appender
log4j.appender.rolling.File=/path/to/log/files/ldapAdminWeb.log

# Configure the maximum size of the log file for the rolling appender
#log4j.appender.rolling.MaxFileSize=4MB

# Keep one backup file of the rolling appender
#log4j.appender.rolling.MaxBackupIndex=5

# Configure the rolling appender to use the PatternLayout
log4j.appender.rolling.layout=org.apache.log4j.PatternLayout

# Configure the conversion pattern for the rolling appender
log4j.appender.rolling.layout.ConversionPattern=%d - %p %c - %m%n




then, in every classes that needs logging I do this:

public class SomeAction
    extends MyBaseAction

    private static Log log = LogFactory.getLog(SomeAction.class);
    ...


    public ActionForward execute (..etc, etc...)
      throws Exception{

     ...
     ...
        log.debug("Delete Item:" + item.getId() +
         "from Catalog:" + cat.getId());
     ...
     ...
    }



Hope that helps you (or anyone following this thread)


>
>
> Pedro Salgado
>
> On 05/12/2003 06:56, "Rahul Mohan" <[EMAIL PROTECTED]> wrote:
>
> > hi nick,
> >
> > thanks for responding...its the logger class thats missing ithink...
> > this is the exception i get when i try to view the page:
> >
> >   java.lang.NoClassDefFoundError: org/apache/log4j/Logger
> >                   at app.LogonAction.perform(Unknown Source)
> >                       ........
> >
> > what could be the problem? please excuse my novice level...
> >
> > thanks again..
> >
> >
> > ----- Original Message -----
> > From: "Nick Faiz" <[EMAIL PROTECTED]>
> > To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
> > Sent: Friday, December 05, 2003 12:22 PM
> > Subject: RE: Log4j with Struts
> >
> >
> >> Well, what class can't it find, the Logger or the LogonAction.class ?
> >>
> >> I use it with Struts, without a hassle, on WebLogic 7.2.
> >>
> >> Nick
> >>
> >> -----Original Message-----
> >> From: Rahul Mohan [mailto:[EMAIL PROTECTED]
> >> Sent: Friday, 5 December 2003 5:46 PM
> >> To: struts
> >> Subject: Log4j with Struts
> >>
> >> Hi,
> >>
> >>     has anybody tried using Log4j with struts? I tried the following code
> >> and its giving a ClassDefNotFoundException during runtime..
> >>
> >> this is inside the perform method:
> >>      String str = new String(LogonAction.class.getName()); //LogonAction
> > is
> >> an Action Class
> >>      logger = Logger.getLogger(str); //this line is throwing the
> > exception -
> >> apparently str is not having a classdef
> >>
> >> somebody please help me with this.....or is there any other method to
> >> perform logging?
> >>
> >> i am using tomcat4.1 ...
> >>
> >> Thanks in advance.
> >>
> >> Rahul Mohan
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >> MasterCraft Group
> >> Tata Consultancy Services
> >> Tata Research Development and Design Center
> >> 54B, Hadapsar Industrial Estate
> >> Pune - 411 013
> >> Phone: +91 4042333 or 4031122 Extn 2556
> >>             +91 20 31544082 ( Mobile )
> >> Fax:     +91 20 4042399
> >> email : [EMAIL PROTECTED]
> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

-- 
James Mitchell
Software Developer / Struts Evangelist
http://www.struts-atlanta.org


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to