log4j is a very popular logging library for Java development. It provides convenient and flexible logging mechanism as well as fast performance.

Putting log4j into your code is pretty easy as it requires minimum of work which mostly involves in configuring the logging system. This article describes the configuration of log4j in details, as well as providing some working examples.

Table of content

  1. Steps to plug log4j into your code
  2. Download log4j
  3. Create log4j’s configuration

4.Code examples

Steps to plug log4j into your code

Typically, the steps to use log4j in your Java application are as follows:

    •          Download latest log4j distribution.
    •           Add log4j’s jar library into your program’s classpath.
    •           Create log4j’s configuration.
    •           Initialize log4j with the configuration.
    •           Create a logger.
    •           Put logging statements into your code.

Download log4j

You can get a distribution of log4j at: http://logging.apache.org/log4j/1.2/download.html

The latest version of log4j is 1.2.17. Download log4j-1.2.17.zip file and extract the archive into a directory you like. The distribution comes with a lot of stuff: documentation, source code, examples… but the only thing we need is the log4j-1.2.17.jar file – log4j’s JAR library.

Add the log4j-1.2.17.jar into compilation classpath and runtime classpath of your project in order to have your code can be compiled and executed with log4j.

 

Recommended Book: Pro Apache Log4j

 

Attachments:
Download this file (BasicLog4jExample.zip)BasicLog4jExample.zip[Basic configuration example]1 kB
Download this file (ProgrammaticLog4jExample.zip)ProgrammaticLog4jExample.zip[Programmatic configuration example]2 kB
Download this file (PropertiesFileLog4jExample.zip)PropertiesFileLog4jExample.zip[Properties file configuration example]2 kB
Download this file (XMLFileLog4jExample.zip)XMLFileLog4jExample.zip[XML file configuration example]2 kB
avatar
how to download a file programatically using in java with example plz give a good soluation....!!!
VOTES:0
avatar
super blog thanks
VOTES:0
Start learning on Udemy today!