Building and Using Log4jBuilding Log4JLog4j 2.x is hosted in the Apache Software Foundation's subversion repository. Details on obtaining the most current source code can be found at Log4j Source Repository. The source from the latest release may be obtained by downloading it using the instructions at Log4j Downloads. Log4j 2.x uses Maven 2 or 3 as its build tool. To build and install Log4j in your local Maven cache, from the root directory run:
mvn install Then to build the full site, you must use a local staging directory:
mvn site [Windows] mvn site:stage-deploy -DstagingSiteURL=file:///%HOME%/log4j [Unix] mvn site:stage-deploy -DstagingSiteURL=file:///$HOME/log4j To rebuild only what's changed and execute the tests, run:
mvn test To rebuild from scratch, add "clean", for example:
mvn clean test Using Log4J on your classpathTo use Log4j 2 in your application make sure that both the API and Core jars are in the application's classpath. Add the dependencies listed below to your classpath.
You can do this from the command line or a manifest file. Using Log4J in your Apache Maven buildTo build with Apache Maven, add the dependencies listed below to your pom.xml file. <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.0-beta6</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.0-beta6</version> </dependency> </dependencies> Using Log4J in your Apache Ivy buildTo build with Apache Ivy, add the dependencies listed below to your ivy.xml file. <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.0-beta6" /> <dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.0-beta6" /> </dependencies> Optional ComponentsLog4j 2.x contains several optional components that can be included in an application. Log4j 1.xIf there are existing components that are written to use Log4j 1.x and it is desired to have this logging routed to Log4j 2 then remove any log4j 1.x dependencies and add the following. <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-1.2-api</artifactId> <version>2.0-beta6</version> </dependency> </dependecies> Apache Commons LoggingCommons Logging is used in many components as a way of letting applications choose the specific logging implementation. To route logging from those components into Log4j 2 include the following dependency and do not remove the Commons Logging jar. <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-jcl</artifactId> <version>2.0-beta6</version> </dependency> </dependencies> SLF4JSLF4J is another popular logging API that may be bound to Log4j 2 by including the following dependency along with the SLF4J dependencies. <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.0-beta6</version> </dependency> </dependencies> Tag LibraryThe Log4j Log Tag Library creates the capability of inserting log statements in JSPs without the use of Java scripting. It uses the standard Log4j 2 API to log messages according to your Log4j configuration. <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-taglib</artifactId> <version>2.0-beta6</version> </dependency> </dependencies> |