What is Log4J. An absolute beginners tutorial.
Chapters
How to install Apache Log4J
Log4j 1.x was widely adopted and used in many applications. However, through the past many years development on it has really slowed down. It has become more difficult to maintain due to its need to be compliant with very old versions of Java. Thus it makes more sense to go on with version 2 of the framework.
Log4j is an open source API package developed and distributed by Apache Software License. The latest version of log4j source code , documentation and class file is available at http://logging.apache.org/log4j/.
After downloading apache-log4j-x.x.x.tar.gz :
Download and extract:
Untar and Unzip downloaded file into /usr/local/ directory:
$ tar -zxvf apache-log4j-2.1-bin.tar
apache-log4j-2.1-bin/LICENSE.txt
apache-log4j-2.1-bin/NOTICE.txt
apache-log4j-2.1-bin/RELEASE-NOTES.txt
apache-log4j-2.1-bin/log4j-api-2.1.jar
apache-log4j-2.1-bin/log4j-api-2.1-sources.jar
apache-log4j-2.1-bin/log4j-api-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-core-2.1.jar
apache-log4j-2.1-bin/log4j-core-2.1-sources.jar
apache-log4j-2.1-bin/log4j-core-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-core-2.1-tests.jar
apache-log4j-2.1-bin/log4j-iostreams-2.1.jar
apache-log4j-2.1-bin/log4j-iostreams-2.1-sources.jar
apache-log4j-2.1-bin/log4j-iostreams-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-jcl-2.1.jar
apache-log4j-2.1-bin/log4j-jcl-2.1-sources.jar
apache-log4j-2.1-bin/log4j-jcl-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-jul-2.1.jar
apache-log4j-2.1-bin/log4j-jul-2.1-sources.jar
apache-log4j-2.1-bin/log4j-jul-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-flume-ng-2.1.jar
apache-log4j-2.1-bin/log4j-flume-ng-2.1-sources.jar
apache-log4j-2.1-bin/log4j-flume-ng-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-1.2-api-2.1.jar
apache-log4j-2.1-bin/log4j-1.2-api-2.1-sources.jar
apache-log4j-2.1-bin/log4j-1.2-api-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-slf4j-impl-2.1.jar
apache-log4j-2.1-bin/log4j-slf4j-impl-2.1-sources.jar
apache-log4j-2.1-bin/log4j-slf4j-impl-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-to-slf4j-2.1.jar
apache-log4j-2.1-bin/log4j-to-slf4j-2.1-sources.jar
apache-log4j-2.1-bin/log4j-to-slf4j-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-jmx-gui-2.1.jar
apache-log4j-2.1-bin/log4j-jmx-gui-2.1-sources.jar
apache-log4j-2.1-bin/log4j-jmx-gui-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-taglib-2.1.jar
apache-log4j-2.1-bin/log4j-taglib-2.1-sources.jar
apache-log4j-2.1-bin/log4j-taglib-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-web-2.1.jar
apache-log4j-2.1-bin/log4j-web-2.1-sources.jar
apache-log4j-2.1-bin/log4j-web-2.1-javadoc.jar
apache-log4j-2.1-bin/log4j-nosql-2.1.jar
apache-log4j-2.1-bin/log4j-nosql-2.1-sources.jar
apache-log4j-2.1-bin/log4j-nosql-2.1-javadoc.jar
During untarring process following directory hierarchy with name apache-log4j-x.x.x will be created with all the jars.
Package installation:
This is optional step and depends on features that are going to be used in log4j framework. There few packages that needs to install for proper working log4j. Some of them are:-
- JavaBeans Activation Framework:JavaBeans Activation Framework is also needs to installed with Java Mail API http://java.sun.com/products/javabeans/jaf/index.jsp.
- Java Message Service: JMS-compatible features of log4j will also require both JMS and JNDI (Java Naming and Directory Interface) be installed on machine http://java.sun.com/products/jms.
- XML Parser:log4j needs XML parser to use log4j for Xerces.jar installed on machine.http://xerces.apache.org/xerces-j/install.html.
Finally:
Next Setup CLASSPATH and PATH for log4j.x.x.x.jar file.
$ pwd
/usr/local/ apache-log4j-2.1
$ export CLASSPATH= \
$CLASSPATH:/usr/local/apache-log4j-2.1/apache-log4j-2.1.jar
$ export PATH=$PATH:/usr/local/apache-log4j-2.1/
Description
This tutorial is aimed at learners who want to get an understaind on what Log4J is and what it is used for. This tutorial have 10 part to it as shown below
- Overview
- How to Install Log4J
- Understanding Architecture
- Getting started with Log4J Configuration
- Sample Program
- Logging Methods
- Understanding different Logging Levels
- Log4J log formatting
- How to log in files
- How to log in database using Log4J
We hope that this tutorial will help you out with Log4J. Please note that this tutorial is for absolute starters and does not go into much depth. Let us know how we can improve by sending your feedback.
Prerequisites
A good understanding of Java programming language is required.
Audience
Absolute beginners
Author: Subject Coach
Added on: 7th Mar 2015
You must be logged in as Student to ask a Question.
None just yet!