
- log4j - Home
- log4j - Overview
- log4j - Installation
- log4j - Architecture
- log4j - Configuration
- log4j - Sample Program
- log4j - Logging Methods
- log4j - Logging Levels
- log4j - ConsoleAppender
- log4j - Logging in Database
Log4j - Formatting Layouts
- log4j - Log Formatting
- log4j - CSV Parameter Layout
- log4j - CSV Log Event Layout
- log4j - HTML Layout
- log4j - Pattern Layout
- log4j - Json Template Layout
Log4j - File Appenders
- log4j - Logging in Files
- log4j - FileAppender
- log4j - Separate Folder per Month
- log4j - Daily log File Generation
log4j Resources
log4j - Installation
log4j API package is distributed under the Apache Software License, a full-fledged open source license certified by the open source initiative.
The latest log4j version, including full-source code, class files and documentation can be found at https://logging.apache.org/log4j/2.x/download.html.
To install log4j on your system, download apache-log4j-2.25.1-bin.zip from the specified URL and follow the steps give below.
Step 1
Unzip the downloaded file in D:\Projects\apache-log4j-2.25.1-bin directory.
Step 2
This step is optional and depends on what features you are going to use from log4j framework. If you already have following packages installed on your machine then it is fine, otherwise you need to install them to make log4j work.
JavaMail API: The e-mail based logging feature in log4j requires the Java Mail API (mail.jar) to be installed on your machine from https://glassfish.org/.
JavaBeans Activation Framework: The Java Mail API will also require that the JavaBeans Activation Framework (activation.jar) be installed on your machine from https://www.oracle.com/java/technologies/?er=221886.
Java Message Service: The JMS-compatible features of log4j will require that both JMS and Java Naming and Directory Interface JNDI be installed on your machine from https://www.oracle.com/java/technologies/?er=221886.
XML Parser: You need a JAXP-compatible XML parser to use log4j. Make sure you have Xerces.jar installed on your machine from http://xerces.apache.org/xerces-j/install.html.
Set CLASSPATH Variable
Set the CLASSPATH environment variable to point to the log4j jar location. Assuming, you have stored log4j and related jars in Projects folder on various Operating Systems as follows.
OS | Output |
---|---|
Windows | Set the environment variable CLASSPATH to %CLASSPATH%;D:\Projects\apache-log4j-2.25.1-bin\log4j-core-2.25.1.jar;D:\Projects\apache-log4j-2.25.1-bin\log4j-api-2.25.1.jar;D:\Projects\apache-log4j-2.25.1-bin\log4j-layout-template-json-2.25.1.jar; |
Linux | export CLASSPATH=$CLASSPATH:Projects/apache-log4j-2.25.1-bin/log4j-core-2.25.1.jar:Projects/apache-log4j-2.25.1-bin/log4j-api-2.25.1.jar:Projects/apache-log4j-2.25.1-bin/log4j-layout-template-json-2.25.1.jar:. |
Mac | export CLASSPATH=$CLASSPATH:Projects/apache-log4j-2.25.1-bin/log4j-core-2.25.1.jar:Projects/apache-log4j-2.25.1-bin/log4j-api-2.25.1.jar:Projects/apache-log4j-2.25.1-bin/log4j-layout-template-json-2.25.1.jar:. |