网站首页 > 技术文章 正文
一、问题背景
在研究spring boot项目内嵌tomcat运行模式的时候发现,AbstractProtocol类中的start方法有日志未打印。
@Override
public void start() throws Exception {
if (getLog().isInfoEnabled()) {
getLog().info(sm.getString("abstractProtocolHandler.start", getName()));
logPortOffset();
}
endpoint.start();
monitorFuture = getUtilityExecutor().scheduleWithFixedDelay(
() -> {
if (!isPaused()) {
startAsyncTimeout();
}
}, 0, 60, TimeUnit.SECONDS);
}
该方法会将当前的运行模式打印出来,类似于:
o.a.coyote.http11.Http11NioProtocol : Starting ProtocolHandler ["http-nio-8080"]
但是,实际启动的时候未找到该日志。
二、项目版本
项目使用spring boot 2.3.12.RELEASE版本,未修改spring boot配置的版本依赖,也未引入其他额外的依赖。
三、问题排查
1、在AbstractProtocol类的start方法增加断点,查看对应的logger信息。
通过查看信息,发现logger的levelIntValue = 900,这表明当时的logger的日志等级为warn,因此这条日志未打印符合程序逻辑。
但是springboot的项目默认等级为info,同时项目并未修改任何日志的打印配置,那为什么这个logger的日志等级为warn呢?
2、通过跟踪代码,找到logger创建的地方(LogManager类的demandLogger方法),发现刚刚创建的logger的日志等级确实为info,因此推断肯定被修改了日志等级。
3、在Logger类的setLevel方法增加断点,确认确实被人修改了日志等级。
4、追述代码,发现在DefaultLogbackConfiguration这个类里面,自定义了部分类的日志打印级别。
private void base(LogbackConfigurator config) {
config.conversionRule("clr", ColorConverter.class);
config.conversionRule("wex", WhitespaceThrowableProxyConverter.class);
config.conversionRule("wEx", ExtendedWhitespaceThrowableProxyConverter.class);
config.logger("org.apache.catalina.startup.DigesterFactory", Level.ERROR);
config.logger("org.apache.catalina.util.LifecycleBase", Level.ERROR);
config.logger("org.apache.coyote.http11.Http11NioProtocol", Level.WARN);
config.logger("org.apache.sshd.common.util.SecurityUtils", Level.WARN);
config.logger("org.apache.tomcat.util.net.NioSelectorPool", Level.WARN);
config.logger("org.eclipse.jetty.util.component.AbstractLifeCycle", Level.ERROR);
config.logger("org.hibernate.validator.internal.util.Version", Level.WARN);
config.logger("org.springframework.boot.actuate.endpoint.jmx", Level.WARN);
}
四、解决方案
因为日志不打印的原因是被修改了日志等级,因为只需要修改其日志打印级别即可。
在application.properties增加如下配置:
logging.level.org.apache.coyote.http11.Http11NioProtocol=INFO
启动项目,查看打印的日志,确实出现这个日志打印。
- 上一篇: 游戏画面绘图 透明特效的制作方法
- 下一篇: 我发现很多程序员都不会打日志……
猜你喜欢
- 2024-12-29 基于 SLF4J 的 MDC 实现日志链路追踪详解
- 2024-12-29 使用Flume同步日志到Kafka flume收集日志到hdfs
- 2024-12-29 Python日志模块logging python logger日志级别
- 2024-12-29 在Spring Boot中通过AOP技术实现日志拦截操作
- 2024-12-29 [编程基础] Python日志记录库logging总结
- 2024-12-29 如何将日志记录到 Windows事件日志 中
- 2024-12-29 SpringBoot集成logback异步日志 springboot集成日志log4j2
- 2024-12-29 Spring Boot中的Logback日志配置详解
- 2024-12-29 Linux 系统日志写入记录命令用法(logger)
- 2024-12-29 Python logging模块日志相关功能及应用示例
- 02-21走进git时代, 你该怎么玩?_gits
- 02-21GitHub是什么?它可不仅仅是云中的Git版本控制器
- 02-21Git常用操作总结_git基本用法
- 02-21为什么互联网巨头使用Git而放弃SVN?(含核心命令与原理)
- 02-21Git 高级用法,喜欢就拿去用_git基本用法
- 02-21Git常用命令和Git团队使用规范指南
- 02-21总结几个常用的Git命令的使用方法
- 02-21Git工作原理和常用指令_git原理详解
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)