当前位置:网站首页>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
边栏推荐
- 微信小程序获取登录用户信息、openid和access_token
- mysql 5.1升级到5.67
- Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
- Algorithem_ReverseLinkedList
- logback-logger和root
- Wechat applet communicates with esp8266 based on UDP protocol
- PyMySQL
- rsync+inotify远程同步
- Cdh6 based on CM management 3.2 cluster integration atlas 2 one
- Kettle -- control parsing
猜你喜欢
RobotFramework 之 项目框架
帆软中需要设置合计值为0时,一整行都不显示的解决办法
按实际取,每三级分类汇总一次,看图知需求
Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动
How QT designer adds resource files
Use of WiFi module based on wechat applet
Kettle -- control parsing
On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
回顾2021:如何帮助客户扫清上云最后一公里的障碍?
MySQL数据库讲解(七)
随机推荐
百度图片识别自定义实现(替代AipOcr)
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
什么是云迁移?云迁移的四种模式分别是?
Operation instructions of star boundary text automatic translator
Wechat applet obtains login user information, openid and access_ token
星界边境文本自动翻译机使用说明
不同时间类型的执行计划计算
RobotFramework 之 用例执行
squid代理
jsp学习3
FBS (fman build system) packaging
Detailed tutorial on the use of smoke sensor (mq-2) (based on raspberry pie 3B +)
org.apache.parquet.schema.InvalidSchemaException: A group type can not be empty. Parquet does not su
redis数据库讲解二(redis高可用、持久化、性能管理)
Promtail + Loki + Grafana 日志监控系统搭建
帆软中需要设置合计值为0时,一整行都不显示的解决办法
基于微信小程序的wifi模块使用
帆软中单元格中隔行变色以及数量大于100字体变大变红设置
连接公司跳板机取别名
某政务云项目业务系统迁移调研实践