日志级别 从小到大
ALL、DEBUG 、INFO、WARA、ERROR 、FATAL 、OFF
ALL(输出所有类型日志)
DEBUG (输出DEBUG 以上级别日志)
INFO(输出INFO以上级别日志)
WARA(输出WARA以上级别日志)
ERROR (输出ERROR 以上级别日志)
FATAL (输出FATAL 以上级别日志)
OFF (关闭日志输出)
日志记录器(Logger)的行为是分等级的:
日志记录器(Logger)是日志处理的核心组件。log4j具有5种正常级别(Level)。:
1.static Level DEBUG :
DEBUG Level指出细粒度信息事件对调试应用程序是非常有帮助的。
2.static Level INFO
INFO level表明 消息在粗粒度级别上突出强调应用程序的运行过程。
3.static Level WARN
WARN level表明会出现潜在错误的情形。
4.static Level ERROR
ERROR level指出虽然发生错误事件,但仍然不影响系统的继续运行。
5.static Level FATAL
FATAL level指出每个严重的错误事件将会导致应用程序的退出。
另外,还有两个可用的特别的日志记录级别:
1.static Level ALL
ALL Level是最低等级的,用于打开所有日志记录。
2.static Level OFF
OFF Level是最高等级的,用于关闭所有日志记录。
log的主要节点
log配置文件主要包含三个节点:Logger、Appender、Layout。
Logger:配置打印日志的级别,输出日志的程序范围,以及关联的Appender。
Appender:配置日志的输出形式,输出策略等。
Layout:配置每条日志的内容格式。
打印日志:
1.在pom文件中导入相关jar包
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
2.在application.yml文件下日志级别控制:
# 日志级别控制
logging:
level:
cn.com.mryhl: debug # 日志级别 从高到低 debug info warn error CRITICAL
org.springframework.boot: info
3.测试:
package cn.com.mryhl.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @description: 测试的Controller
* @author: mryhl
* @date: Created in 2020/10/31 17:27
* @version: 1.1
* @RestController 相当于 @Controller+ @ResponseBody
*/
@RestController
@Slf4j
public class HelloController {
@GetMapping("/hello")
public String hello(){
//System.out.println("HelloController中的hello方法执行了");
log.debug("HelloController中的hello方法执行了");
return "HelloController中的hello方法执行了";
}
}
4. 测试结果
其中:
logging.level:是固定写法,说明下面是日志级别配置,日志相关其它配置也可以使用。
cn.com.mryhl和org.springframework是指定包名,后面的配置仅对这个包有效。
debug:日志的级别 常用的级别有4个 debug info warn error