Tomcat控制台总是打印日志问题的解决办法
问题
使用gradle启动项目,在tomcat控制台中不停地打印perf4j性能日志,导致开发过程很卡很慢。明明修改了logback.xml配置文件,让它输出到log文件中,而不是控制台,但是不起作用。
在Windows系统中,在启动tomcat后会出现上图这样的情况,
在ubuntu系统中,没有这种情况,应该是在ubuntu系统中,没有tomcat的控制台吧。
同样,部署在线上的时候也没有问题。
唯独在windows中进行开发的时候有问题。
解决过程
真的是尝试很久很久。
刚开始调整日志打印路径,无果;
然后就是调整日志打印级别,只打印Error的,这个实现了,却仍然打印;
最后决定替换tomcat的Jar包里的代码,不让它打印日志了,解决问题。
Jar包中性能打印的语句为:
StopWatch stopWatch = new Log4JStopWatch("Messages.searchFiles");
try {
......
} finally {
stopWatch.stop();
}
调用的perf4j-*.jar包中的方法
public Log4JStopWatch(String tag) {
this(tag, null, Logger.getLogger(DEFAULT_LOGGER_NAME), Level.INFO, Level.WARN);
}
而这个方法最终打印在控制台上的语句为:
protected void log(String stopWatchAsString, Throwable exception) {
logger.log((exception == null) ? normalPriority : exceptionPriority, stopWatchAsString, exception);
}
再跟踪这个方法,跳转到了log4j-*.jar包中的 Category.java类中的log 方法
public void log(Priority priority, Object message, Throwable t) {
if(repository.isDisabled(priority.level)) {
return;
}
if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, priority, message, t);
}
再跳转时:
protected void forcedLog(String fqcn, Priority level, Object message, Throwable t) {
callAppenders(new LoggingEvent(fqcn, this, level, message, t));
}
再往后就是具体打印的方法了。
之前问题的所有打印日志的方法都会走到这里,于是我把这个jar包中的log方法和forcedLog方法的内容都删除了,然后替换原来的log4j-*.jar包,实现效果。
这里提供一个修改后的jar包:
链接:https://pan.baidu.com/s/1078F50P8UuWW-Hgxt36QbQ 密码:j4w9
但如果是maven项目,不能直接替换jar包,可以根据tomcat的加载优先级,将修改后的jar包放到tomcat 中的lib 目录下进行覆盖
具体参考:http://www.cnblogs.com/acm-bingzi/p/webModifyJar.html
原创文章,欢迎转载,转载请注明出处!
相关文章
- Tomcat-connector的微调(3): processorCache与socket.processorCache
- Tomcat日志输出乱码的解决方式
- 在系统下文件上传报错:The temporary upload location [/tmp/tomcat.xxx/work/Tomcat/localhost/ROOT] is not valid
- Tomcat 配置 项目 到tomcat目录外面 和 域名绑定访问(api接口、前端网站、后台管理网站)
- spring boot tomcat 打本地包成war,通过Tomcat启动时出现问题: ZipException: error in opening zip file
- 如何安装Tomcat
- Eclipse整合Tomcat开发Dynamic Web Project环境总结
- Eclipse TOMCAT 插件:Sysdeo Tomcat Launcher Plugin
- tomcat错误信息解决方案【严重:StandardServer.await: create[8005]
- 转 一台电脑安装多个tomcat
- Tomcat 系统架构与设计模式
- Tomcat详解(十一)——Tomcat管理
- Tomcat详解(三)——tomcat多实例
- IntelliJ IDEA部署tomcat时Edit Configuration无artifact选项
- Tomcat卷二---请求流程源码分析
- Eclipse Server runtime设置里找不到apache tomcat的处理方法
- Atitit webserver tomcat 7 8.0 8.5 9.0新特性 Tomcat 7 的七大新特性 - 编程语言 - ITeye资讯.html tomcat 8.0特性 - CSD
- Tomcat的Manager显示403 Access Denied
- tomcat中jsp引用图片img的src属性带中文路径无法显示的解决
- eclipse下启动tomcat项目,访问tomcat默认端口显示404错误
- Ngnix、Tomcat和HTTP Server
- Spring Mvc和Spring Boot配置Tomcat支持Https
- 008-tomcat源码阅读-查看源码、日志配置、启动配置、启动
- 007-tomcat 下多个War发布详解步骤[同一个Tomcat 同一个端口 部署多个项目、同一个Tomcat 多个端口 部署多个项目]
- Tomcat服务器的默认端口是多少?怎样修改tomcat的端口?
- Tomcat tomcat-users.xml帮你登录Server Status