Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | About

第 18 章 Log

目錄

18.1. Logback
18.1.1. Maven 包
18.1.2. Example
18.2. slf4j
18.3. log4j
18.3.1. 安裝 Log4j
18.3.1.1. 手工安裝
18.3.1.2. Maven
18.3.2. log4j 環境變數
18.3.3. Log4j Example
18.3.4. log4j.properties

18.1. Logback

http://logback.qos.ch/index.html

Logback 是 log4j 作者開發,目前的趨勢Log4j逐步被Logback取代。

18.1.1. Maven 包

			
		<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.25</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-core -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-core</artifactId>
			<version>1.2.3</version>
		</dependency>
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-access</artifactId>
			<version>1.2.3</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
		<dependency>
			<groupId>ch.qos.logback</groupId>
			<artifactId>logback-classic</artifactId>
			<version>1.2.3</version>
		</dependency>
			
			

18.1.2. Example

			
package com.logs;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyApp {
	final static Logger logger = LoggerFactory.getLogger("MyApp.class");
	public static void main(String[] args) {
         
		logger.trace("trace");
		logger.debug("debug str");
		logger.info("info str");
		logger.warn("warn");
		logger.error("error");
	}
}