Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use log4j2 Commons Logging Bridge

I want to use log4j2 Commons Logging Bridge with commons 1.2. I tried to use something like follows:

import org.apache.logging.log4j.jcl.LogFactoryImpl;

public class MyClass{

    private static Log log = LogFactoryImpl.getLog(DropinsBundleDeployer.class);
         .
         .
         .
    log.error("Error occured", e);
}

But when I'm running the code I'm getting following issue and cannot see any log:

log4j:WARN Please initialize the log4j system properly.

However the log4j2.xml file is in the class path. How can I correctly use commons logging 1.2 with log4j2 ?

like image 456
Grant Avatar asked Apr 23 '15 09:04

Grant


People also ask

Does Commons Logging work with log4j2?

Apache Commons Logging (previously known as Jakarta Commons Logging or JCL) is a thin adapter allowing configurable bridging to other, well-known logging systems like Log4J, LogKit. But through wrappers, you can use commons-logging with any other logging systems like log4j2, SLF4J, LogBack, etc.

Does Commons Logging uses Log4j?

The Commons Logging Bridge allows applications coded to the Commons Logging API to use Log4j 2 as the implementation.

Is Commons Logging the same as Log4j?

log4j is a logging framework, i.e. it provides the code to log messages. Commons-logging is an abstraction layer for logging frameworks, it doesn't log anything itself.

What is the use of Commons Logging?

Apache Commons Logging (previously known as Jakarta Commons Logging or JCL) is a Java-based logging utility and a programming model for logging and for other toolkits. It provides APIs, log implementations, and wrapper implementations over some other tools.


1 Answers

You may want to look at the FAQ page on which jars you need.

You will need the following jars on the classpath:

  • log4j-api-2.2
  • log4j-core-2.2
  • log4j-jcl-2.2
  • commons logging

Also please ensure that log4j-1.2 is not in your classpath. That error messages looks like a log4j-1.2 error...

like image 53
Remko Popma Avatar answered Sep 22 '22 15:09

Remko Popma