More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Use of BasicConfigurator in Log4j logging

                         

log4j warning

log4j: WARN No appenders could be found for logger (org.activemq.transport.tcp.TcpTransportChannel).
log4j: WARN Please initialize the log4j system properly.

If  you are getting foregoing log4j warn debug info, that means you have not initialized log4j properly. So
In this part of tutorial we will tell you how to configure log4j using BasicConfigurator.

Now lets see when this log4j warning occurs. We are creating only SimpleLog file without configuring it as:

 

 

 

 

 

import org.apache.log4j.*;
public class SimpleLog {
  static Logger logger = Logger.getLogger("SimpleLog.class");
  public static void main(String[] args) {
    logger.debug("Hello world.");  
    }
}

After running the example we have got following log4j warning flashing on command prompt:

log4j:WARN No appenders could be found for logger (SimpleLog.class).
log4j:WARN Please initialize the log4j system properly.

It is because we don't have configured Log4j. There are many different ways of configuring Log4j. One way is through BasicConfigurator. This can be done as follows:

import org.apache.log4j.*;
import org.apache.log4j.BasicConfigurator;
public class SimpleLog {
  static Logger logger = Logger.getLogger("SimpleLog.class");
  public static void main(String[] args) {
    BasicConfigurator.configure();
    logger.debug("Hello world.");  
    }
}

Now after running this code you will get the following output on your console:

Output:

0 [main] DEBUG SimpleLog.class - Hello world.

where "0" shows time taken in milliseconds from start of program to the logging request. "Hello world" is the message that we have given.
SimpleLog.class is the logger name and in bracket [main] is the thread who have invoked logging.

Download Source Code

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Join and Excel yourself with our Online instructor led training sessions
Training Courses
Tell A Friend
Your Friend Name

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.