Questions:Ask|Latest


 
 

Share on Google+Share on Google+

log4j

Advertisement
This Example shows you how to create a log in a program.

Log4J Tutorial - Log4J Examples in Java

                         

In this tutorial you will learn about Log4J, which is one of the most used Logging API by the Java programmers. It is fast and easy to use and provides customizable log formats. Here we are providing many examples of the Log4J framework.

Log4J is an Open Source logging framework from the apache foundation. It's a Java based framework and can be used in any java program. It was originally developed by Ceki Gülcü  and now its part of Apache Software project.

It can be used by the Java programmers to add logging functionality in the projects. These days most of the Java projects uses Apache Log4J for logging.

It provides powerful yet efficient and fast API for the Java programmers. Java programmers easily uses Log4J in their code to log the error and information messages into a log file.

Log4j simply inserts a log statement in the application code and manage them externally without going back to its application source code. Programmer's can control the logging message with the help of external configuration file e.g. log4.xml or log4j.properties file. The external properties file can be used to set the log format as well as the level of logging  (DEBUG, INFO, FATAL etc..)

Let's get started with the Log4J framework:

  1. Log4J is leading logging Framework in Java
     
  2. Log4J Architecture
    In this section we will understand the architecture of Log4J framework.
     
  3. A simple example of log4j
    This Example shows you how to create a log in a program.
             
  4. log4j example
    This Example shows you how to create a log in a Servlet.
              
  5. Use of BasicConfigurator in Log4j logging
    In earlier example you have seen that we can define properties of log4j logging file with the help of log4j.properties. Properties can also be defined within log4j.xml file.
             
  6. log4j.xml Example
    In earlier example you have seen that we can define properties of log4j logging file with the help of log4j.properties. Properties can also be defined within log4j.xml file.
            
  7. Console Appender in Log4j
    In this log4j console appender tutorial  you will be introduced with ConsoleAppender which is used in Log4j for appending output on the console each and every time when any info(), debug(), error() method is invoked by the logger.
                 
  8. FileAppender in Log4j
    In previous section we have used ConsoleAppender to append log events. We can also append these log events to a file by using FileAppender.
              
  9. WriterAppender in Log4j
    In our previous section we have seen that we can append log events in simple file (plain/text) file and to the console also. If we want to write files then we have to use WriterAppender.
              
  10. Layouts in Log4j
    Users more often wish to customize their output according to their output format. Layout can be set by attaching it with the appender. The Layout is responsible for formatting the logging output.
            
  11. Use of SimpleLayout in Log4j
    In the previous example we have studied that there are many Layout classes for displaying logging output in the desired format. In this section we are going to describe you one of them, SimpleLayout, the simplest of all.
               
  12. Use of XMLLayout in Log4j
    In the previous sections we have used PatternLayout and SimpleLayout, now we are going to describe you how to use XMLLayout class to produce logging output in the XML format.
             
  13. TTCCLayout in Log4j
    In the previous example we have studied that there are many Layout classes for displaying logging output in the desired format. 
            
  14. Use of HTMLLayout in Log4j
    In this section we will describe you about HTMLLayout class. This layout outputs events in a HTML table. Appenders using this layout should have their encoding set to UTF-8 or UTF-16, otherwise events containing non ASCII characters could result in corrupted log files. 
                       
  15. A simple example of log4j for Servlet
    This Example shows you how to create a log in a Servlet.

                         

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2009

Ask Questions?    Discuss: log4j  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com