Sunday, September 21, 2014

Log4j 2 Migration Tutorial : Solve ERROR StatusLogger Could not search jar file 'C:\EAP-6.2.0\jboss-eap-6.2\standalone\deployments\myPorject.war\WEB-INF\lib\log4j-core-2.0.2.jar\org\apache\logging\log4j\core

Removed
I was working with Log4j-1.2, but have decided to move to Log4j-2.0. I have hence removed the old dependencies and add the new ones.





<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-core</artifactId>
 <version>2.0.2</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-slf4j-impl</artifactId>
  <version>2.0.2</version>
</dependency>

Once done, I deployed my application but got this error:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

 ERROR StatusLogger Could not search jar file 'C:\EAP-6.2.0\jboss-eap-6.2\standalone\deployments\myProject.war\WEB-INF\lib\log4j-core-2.0.2.jar\org\apache\logging\log4j\core' for classes matching criteria: annotated with @Plugin file not found java.io.FileNotFoundException: C:\EAP-6.2.0\jboss-eap-6.2\standalone\deployments\drl_m2m.war\WEB-INF\lib\log4j-core-2.0.2.jar\org\apache\logging\log4j\core (The system cannot find the path specified)


In fact, using Log4j 2.0, we need to make some changes on the Log4j file :

- Step 1 : Rename it to log4j2.xml. Change also the file structure.



<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="com.myproject" level="trace">
      <AppenderRef ref="Console"/>
    </Logger>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>


- Step 2 : Change the dependencies to use the 2.0 and no more 1.2 libraries.

- Step 3Remove all the log4j filters and listeners from the web.xml According to this JIRA.

- Step 4: Exclude any dependency to old versions of log4j.



<dependency>
 <groupId>common_m2m</groupId>
 <artifactId>common_m2m</artifactId>
 <version>${project.version}</version>
 <exclusions>
  <exclusion>
   <artifactId>log4j</artifactId>
   <groupId>log4j</groupId>
  </exclusion>
 </exclusions>
</dependency>

- Step 5: Change the call in the java code.



import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

public class MyClass {

 private Logger logger = LogManager.getLogger(MyClass.class);

}

That's all for this post, hope you enjoyed it and thanks for my friend Hassen Kalaldeh for his help.

7 comments :

  1. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This comment has been removed by a blog administrator.

      Delete
  2. Thank you very much, without your help I wouldn't realize that I can't use log4.properties anymore. Thank you! :)

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete

Articles les plus consultés