Libraries
Articles

Log4j

From Libzter

Share/Save/Bookmark
Jump to: navigation, search


Log4j

Developer(s)Apache
Initial Release
Current Version1.2
Language(s)Java
Licence(s)Apache license
Platform(s)Cross Platform


Contents

[edit] Overview

Log4j is a simple and highly configurable logging library for Java projects. Log4j is governed by the apache foundation official site. One of the biggest asset off using Log4j is that you can configure different appenders which enables you to get the your logging as it may fit you (ex. File, Database, JMS and so on). With Log4j you are also able to specify the layout of your logging. Log4j is an open source project and comes with an apache license.

[edit] Specifications

Log4j requires you to run JDK1.3 or greater.

[edit] Features

  • Flexible logging of Java applications
  • Configurable logging level of Packages/Classes
  • Configurable appenders for logging output
  • Different Patterns for the logging

[edit] Log Levels

Log levels are a number of levels that log4j is able to log to. The levels are DEBUG, INFO, WARN, ERROR, FATAL. When a program that implements log4j runs it defines on what specific level that it wants to log on and all messages that correspond to that and higher level (DEBUG lowest, FATAL highest) will then be logged to the output.

[edit] Configuration

The configuration of log4j can be done in a simple property file or an XML file. In the configuration you can configure what Appenders (small program/classes that handle log4j output to different mediums ex file, db) you want, what level they will log on and in some cases how the output will look like. configuration reference

[edit] Installation

You will have to copy the Log4j jar file and make sure it is included in you classpath. You will also have to create a Log4j configuration file that is loaded when your program starts.

[edit] Usage

 package com.foo;
 import org.apache.log4j.Logger;
 
 public class Foo {
   static Logger logger = Logger.getLogger(Foo.class);
 
   public void execute() {
     logger.info("Executing Foo");
   }
 }

[edit] Extendabiblity

  • Write your own Log4j appender - It is quite easy to write your own appender.
  • Write your own logging layouts - You are also able to write your own layout that will formate the output log message.

Library Navigation

  • Language

  • Category
Google AdSense