MANJUNATH
MANJUNATH

Reputation: 11

how to create the log4j file and run the programme

Now I am learner to log4j , please guide me how to create and the run simple example step by step.

Upvotes: 0

Views: 1901

Answers (3)

Aayush Tuladhar
Aayush Tuladhar

Reputation: 91

Basics and Intermediate Example for log4j

http://aayushtuladhar.wordpress.com/2012/12/01/testtt/

Best Doc for log4j

http://logging.apache.org/log4j/1.2/manual.html

Upvotes: 0

aioobe
aioobe

Reputation: 420951

From Log4J Java - A simple Log4J example

package com.devdaily.log4jdemo;

import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * A simple Java Log4j example class.
 * @author alvin alexander, devdaily.com
 */
public class Log4JExample
{
  // our log4j category reference
  static final Category log = Category.getInstance(Log4JDemo.class);
  static final String LOG_PROPERTIES_FILE = "lib/Log4J.properties";

  public static void main(String[] args)
  {
    // call our constructor
    new Log4JExample();

    // Log4J is now loaded; try it
    log.info("leaving the main method of Log4JDemo");
  }

  public Log4JExample()
  {
    initializeLogger();
    log.info( "Log4JExample - leaving the constructor ..." );
  }

  private void initializeLogger()
  {
    Properties logProperties = new Properties();

    try
    {
      // load our log4j properties / configuration file
      logProperties.load(new FileInputStream(LOG_PROPERTIES_FILE));
      PropertyConfigurator.configure(logProperties);
      log.info("Logging initialized.");
    }
    catch(IOException e)
    {
      throw new RuntimeException("Unable to load logging property " +
                                  LOG_PROPERTIES_FILE);
    }
  }
}

Upvotes: 2

willcodejavaforfood
willcodejavaforfood

Reputation: 44063

Log4J Manual...

Upvotes: 1

Related Questions