Solved

log4j

Posted on 2008-06-15
9
531 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is the difference between "sudo su" and "su - root" 6 104
recursion example 16 111
custom annotations 9 31
servlet filter example 37 41
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

911 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

26 Experts available now in Live!

Get 1:1 Help Now