简体   繁体   中英

Log4j2 - configuring

I am trying to adopt Log4j2 in my new project, but I get my logs in catalina.out<\/code> , and the first one is always: ERROR StatusLogger Unable to locate a logging implementation, using SimpleLogger<\/code> . It seems that I have done everything according to Log4j2 docs, but still.

  1. <\/li>
  2. <\/li>
  3. <\/li><\/ol>

    I am using Tomcat 7, MacOS X 10.8, Java 7.

I had the same problem. After adding also log4j-core-2.0-beta3.jar to the classpath it worked.

In Maven you normally have this logging configuration:

<properties>    
    <slf4j-version>1.7.7</slf4j-version>
    <slf4j-log4j2-version>2.0.1</slf4j-log4j2-version>
</properties>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j-version}</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>${slf4j-log4j2-version}</version>
</dependency>

To add the log core lib you have to:

  1. Add the 2.0.1 to the properties section
  2. Add the log core dependency:

     <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j2-version}</version> </dependency> 

新图标 Updated to the version 2.7

Add the next jars to your project:

If you are using Maven, add the dependency:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.7</version>
</dependency>

我使用log4j2.8.2并通过将log4j2.xml放入web classes文件夹(WEB-INF / classes / log4j2.xml)让它成功自动配置

If it's maven project, you have to add the below dependency,

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.17.1</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.17.1</version>
</dependency>

And the log4j2.xml or log4j2.properties file should be under src/main/resources folder. In that case you don't need to explicitly add folder or jars in classpath. It should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM