Solved

log4j

Posted on 2008-06-15
9
533 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:komlaaa
  • 5
  • 3
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21790219
you need to specify debug level for the package that class belongs to
0
 
LVL 2

Expert Comment

by:themuppeteer
ID: 21794053
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

0
 

Author Comment

by:komlaaa
ID: 21813528
>>
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

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:komlaaa
ID: 21817390
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

0
 
LVL 92

Expert Comment

by:objects
ID: 21818345
by adding this to your original properties file

log4j.logger.action=DEBUG, stdout


0
 

Author Comment

by:komlaaa
ID: 21819441
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
0
 
LVL 92

Expert Comment

by:objects
ID: 21819458
is WARN logging showing up from that class?

0
 

Author Comment

by:komlaaa
ID: 21820704
>> 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
0
 

Accepted Solution

by:
komlaaa earned 0 total points
ID: 21825520
Well,... i got this working by chance i think. Attached below is the log4j.properties version that works for me.

Note that i did not have to add: log4j.logger.action=DEBUG, stdout

However i think the below is crutial:
log4j.appender.stdout.Target=System.out


log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=warn, stdout
 
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

0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

821 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