两种常用日志框架搭配快速上手
# SLF4J+LogBack用法
# 依赖
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 基本用法
/**
* @author blog.unclezs.com
* @date 2020/12/1 10:46 下午
*/
public class LogbackSample {
static final Logger logger = LoggerFactory.getLogger(LogbackSample.class);
public static void main(String[] args) {
logger.info("log by Logback");
logger.warn("log by Logback");
logger.error("log by Logback");
logger.debug("log by Logback");
logger.trace("log by Logback");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 如何配置logback.xml
Logback 配置官方文档 (opens new window)
# Common-Logging+Log4J的用法
# 依赖
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 基本用法
/**
* @author blog.unclezs.com
* @date 2020/12/1 10:50 下午
*/
public class Log4jSample {
public static void main(String[] args) {
Logger logger = LogManager.getLogger(Log4jSample.class);
logger.info("log by log4j2");
logger.warn("log by log4j2");
logger.error("log by log4j2");
logger.debug("log by log4j2");
logger.trace("log by log4j2");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 配置log4j2.xml
在 GitHub 编辑此页 (opens new window)
上次更新: 2024/02/25, 12:11:11