logback,log4j和log4j2的区别

1.logback的使用,参考:logback的使用和logback.xml详解

pom文件

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <logback.version>1.1.7</logback.version>
  <slf4j.version>1.7.21</slf4j.version>
</properties>

<dependencies>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>${logback.version}</version>
  </dependency>
  <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>${logback.version}</version>
    </dependency>
</dependencies>

代码

import org.slf4j.Logger
import org.slf4j.LoggerFactory

private static final Logger log = LoggerFactory.getLogger(LoggingDemo.class);

    

2.log4j的使用

pom文件

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

代码

import org.apache.log4j.Logger;

private final Logger LOGGER = Logger.getLogger(LoggingDemo.class.getName());

   

3.log4j2的使用,参考:浅谈Log4j和Log4j2的区别

pom文件

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

代码

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

private static Logger logger = LogManager.getLogger(LoggingDemo.class.getName());

  

  

 

posted @ 2016-02-11 12:56  tonglin0325  阅读(484)  评论(0编辑  收藏  举报