Solved

log4j

Posted on 2008-06-15
9
537 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
[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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
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:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

623 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