Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

log4j

Posted on 2008-06-15
9
Medium Priority
?
541 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

885 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