当前位置:网站首页>Logback logger and root
Logback logger and root
2022-04-23 14:12:00 【All the names I thought of were used】
One 、root and logger
<logger> Used to set the log printing level of a package or a specific class 、 And the designation appender. It can contain zero or more <appender-ref> Elements , Identify this appender Will be added to this logger.
<root> It's also <logger> Elements , But it's a root logger, only one level attribute , Because of its name Namely ROOT
Next, let's talk about logger and root Use
scene
logback To configure
<logger name="com.codexie.controller.demo1" level="debug">
<appender-ref ref="Stdout" />
<appender-ref ref="RollingFile" />
</logger>
<logger name="com.codexie.controller.demo2" level="warn"></logger>
<!-- Log output level -->
<root level="info">
<appender-ref ref="Stdout" />
<appender-ref ref="RollingFile" />
</root>
We can see demo1 Of level Set to debug,demo2 Of level by warn, and root Of level by info
controller
@Controller
public class demo1 {
private static final Logger logger = LoggerFactory.getLogger(demo1.class);
@RequestMapping("demo1")
@ResponseBody
public String logBack(){
logger.debug("demo1:logback debug");
logger.info("demo1:logback info");
return "ok";
}
}
@Controller
public class demo2 {
private static final Logger logger = LoggerFactory.getLogger(demo2.class);
@RequestMapping("demo2")
@ResponseBody
public String logBack(){
logger.info("demo2:logback run");
logger.debug("demo2:logback info");
logger.warn("demo2:logback warn");
return "ok";
}
}
visit demo1
You can see that the same message has been printed twice , because demo1 Of level yes debug, therefore debug and info All levels of information can · Print , Again because logger and root There are appender, So the same message is printed twice .
visit demo2
visit demo2 Only one message was printed , because demo2 Of level by warn, So it won't print debug and info Level information , Only print warn Level information , Again because demo2 Of logger No configuration appender, So use root Of appender Print once .
Scenario two
<logger name="com.codexie.controller.demo1" level="debug"> </logger>
<logger name="com.codexie.controller.demo2" level="warn"></logger>
<!-- Log output level -->
<root level="info">
<appender-ref ref="Stdout" />
<appender-ref ref="RollingFile" />
</root>
We will demo1 Of appender And cancelled , Verify to see if demo1 The log information of is only printed once
Verify success , The conclusion is correct
版权声明
本文为[All the names I thought of were used]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231404419674.html
边栏推荐
- 帆软分割求解:一段字符串,只取其中某个字符(所需要的字段)
- RecyclerView高级使用(二)-垂直拖拽排序的简单实现
- 利用json-server在本地创建服务器请求
- MYSQL 主从同步避坑版教程
- squid代理
- VMware installation 64 bit XP Chinese tutorial
- 按实际取,每三级分类汇总一次,看图知需求
- jsp学习1
- Recyclerview advanced use (II) - simple implementation of vertical drag and drop sorting
- Intégration de Clusters CDH Phoenix basée sur la gestion cm
猜你喜欢
随机推荐
RobotFramework 之 公共变量
MySQL数据库讲解(八)
sql中出现一个变态问题
On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
Nifi 快速安装及文件同步操作
leetcode--357. Count the number of different figures
帆软之单元格部分字体变颜色
RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
Recyclerview advanced use (I) - simple implementation of sideslip deletion
Algorithem_ReverseLinkedList
mysql 5.1升级到5.67
GFS分布式文件系统(理论)
关于Jmeter启动闪退问题
微信小程序与低功耗蓝牙通信-往硬件端发送数据(三)
基於CM管理的CDH集群集成Phoenix
Check in system based on ibeacons
帆软调用动态传参的方法,在标题中设置参数
findstr不是内部或外部命令解决方法
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
云迁移的六大场景