Solved

log4j

Posted on 2008-06-15
9
530 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now