Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

第 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");
	}
}