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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With