Link to home
Start Free TrialLog in
Avatar of komlaaa
komlaaa

asked on

log4j

In my webap involving tomcat, strut, hibernate. Every is working fine.  I have also setup log4j but unable to print debug output to the console. Please see snippets:
public class CreateCustomerAction extends AbstractAction {
....................
    private static Log log = LogFactory.getLog(CreateCustomerAction.class );
.....................
 if ( log.isDebugEnabled() ){
        	log.debug("just read firstName:"+ fn
        			+", lastName: " + ln 
        			+", emailAddress: "+ ad
        			+", custumerID: " + custId);
        }
 
 
 
log4j.properties:
=================
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss}
(%F:%M:%L)%n%m%n%n
 
log4j.logger.org.apache.struts=DEBUG
org.hibernate.SQL=DEBUG
org.hibernate.type=DEBUG
org.hibernate.tool.hbm2ddl=DEBUG
org.hibernate.pretty=DEBUG
org.hibernate.cache=DEBUG
org.hibernate.transaction=DEBUG
org.hibernate.jdbc=DEBUG
org.hibernate.hql.ast.AST=DEBUG
org.hibernate.secure=DEBUG
org.hibernate=DEBUG

Open in new window

Avatar of Mick Barry
Mick Barry
Flag of Australia image

you need to specify debug level for the package that class belongs to
you don't need
" if ( log.isDebugEnabled() ){"

and perhaps you could try log4j.rootLogger=DEBUG

are you sure the properties file is on the classpath ? try a system.out after your  if ( log.isDebugEnabled() )


br,
themuppeteer

http://users.telenet.be/free_quiz

Avatar of komlaaa
komlaaa

ASKER

>>
you need to specify debug level for the package that class belongs to

How?

>>
and perhaps you could try log4j.rootLogger=DEBUG
i did and when it start tomcat i end up in an  infinite loop on my c: prompt tomcat console

Thanks

Avatar of komlaaa

ASKER

i use this is example(http://www.theserverside.com/discussions/thread.tss?thread_id=31659)
to create the property file below but i am still not getting any log output,... can someone help?

package actions;
...........
public class CreateCustomerAction extends AbstractAction {
	
    private static Log log = LogFactory.getLog(CreateCustomerAction.class);
.............
      if (log.isDebugEnabled()){
        	log.debug("just read firstName:"+ fn
        			+", lastName: " + ln 
        			+", emailAddress: "+ ad
        			+", custumerID: " + custId);
        }
    
the current log4j.properties file
=================================
log4j.logger.actions=DEBUG,CreateCustomerAction
 
llog4j.appender.CreateCustomerAction=org.apache.log4j.FileAppender
log4j.appender.CreateCustomerAction.File=createCustomerAction.log
log4j.appender.CreateCustomerAction.layout=org.apache.log4j.PatternLayout
log4j.appender.CreateCustomerAction.layout.ConversionPattern=%d{MM-dd@HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
 
log4j.logger.org.apache.struts=DEBUG
org.hibernate.SQL=DEBUG
org.hibernate.type=DEBUG
org.hibernate.tool.hbm2ddl=DEBUG
org.hibernate.pretty=DEBUG
org.hibernate.cache=DEBUG
org.hibernate.transaction=DEBUG
org.hibernate.jdbc=DEBUG
org.hibernate.hql.ast.AST=DEBUG
org.hibernate.secure=DEBUG
org.hibernate=DEBUG

Open in new window

by adding this to your original properties file

log4j.logger.action=DEBUG, stdout


Avatar of komlaaa

ASKER

i added "log4j.logger.actions=DEBUG, stdout"  but still can't haave an output of what i added in my class.

The output generated is shown on screen shot added

Please see below the current log4J.properties.
log4j.rootLogger=WARN, stdout
log4j.logger.actions=DEBUG, stdout
 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss}
(%F:%M:%L)%n%m%n%n
 
log4j.logger.org.apache.struts=DEBUG
org.hibernate.SQL=DEBUG
org.hibernate.type=DEBUG
org.hibernate.tool.hbm2ddl=DEBUG
org.hibernate.pretty=DEBUG
org.hibernate.cache=DEBUG
org.hibernate.transaction=DEBUG
org.hibernate.jdbc=DEBUG
org.hibernate.hql.ast.AST=DEBUG
org.hibernate.secure=DEBUG
org.hibernate=DEBUG

Open in new window

log4j.JPG
is WARN logging showing up from that class?

Avatar of komlaaa

ASKER

>> is WARN logging showing up from that class?
After i inserted these lines in that class, i have the screen shot below: note some WARN printed there. So, yes WARN is showing there.

           if (logger.isWarnEnabled()){
             logger.warn("just read firstName:"+ fn
                         +", lastName: " + ln
                         +", emailAddress: "+ ad
                         +", custumerID: " + custId);
      }


log4j.JPG
ASKER CERTIFIED SOLUTION
Avatar of komlaaa
komlaaa

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