Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Log4J environment variable need both core and api JAR's?

When installing Log4J, we need to have two variables in the system classpath :

log4j-api
log4j-core

The log4j-api variable looks like this :

log4j-api : C:\apache_log4j_beta5\apache-log4j-2.0-beta5-bin\log4j-api-2.0-beta5.jar

And the log4j-core variable looks like this :

log4j-core: C:\apache_log4j_beta5\apache-log4j-2.0-beta5-bin\log4j-core-2.0-beta5.jar

Both of these env. variables go into the overlapping LOG4J_HOME variable :

LOG4J_HOME - %log4j-api%;%log4j-core%

Why does it need both the api and core libraries(JAR files) though? When I import a class, I say :

import org.apache.logging.log4j.Logger;

So which of the above JAR's get searched for here? Is it core or api ? any tips appreciated, thanks

like image 517
Caffeinated Avatar asked Jul 05 '15 21:07

Caffeinated


1 Answers

log4j-api, as it's name says is an API. So basically it just contains interfaces that you can use to interface your code with the log4j framework. log4j-core is the implementation of this interface, so it contains actual code. It implements every interface in the API.

So basically when you import the Logger class, you import it from the API library. And when you call LogManager.getLogger() it first initializes itself in a static block, and it will try to search for valid implementations. And that's why you need the core library too.

like image 77
Rothens Avatar answered Sep 28 '22 03:09

Rothens