今天和同事讨论一个问题,log.error("eee{}","11111",e); 能否打印出异常堆栈的问题,在我的印象里,

org.slf4j.Logger 类里的error的重载的方法里面只有2个参数的,最后一个参数为Throwable类型的入参 (标红颜色的),其他都为第一个模板参数format的动态参数
/*** Log a message at the ERROR level.** @param msg the message string to be logged*/
public void error(String msg);/*** Log a message at the ERROR level according to the specified format* and argument.* <p/>* <p>This form avoids superfluous object creation when the logger* is disabled for the ERROR level. </p>** @param format the format string* @param arg    the argument*/
public void error(String format, Object arg);/*** Log a message at the ERROR level according to the specified format* and arguments.* <p/>* <p>This form avoids superfluous object creation when the logger* is disabled for the ERROR level. </p>** @param format the format string* @param arg1   the first argument* @param arg2   the second argument*/
public void error(String format, Object arg1, Object arg2);/*** Log a message at the ERROR level according to the specified format* and arguments.* <p/>* <p>This form avoids superfluous string concatenation when the logger* is disabled for the ERROR level. However, this variant incurs the hidden* (and relatively small) cost of creating an <code>Object[]</code> before invoking the method,* even if this logger is disabled for ERROR. The variants taking* {@link #error(String, Object) one} and {@link #error(String, Object, Object) two}* arguments exist solely in order to avoid this hidden cost.</p>** @param format    the format string* @param arguments a list of 3 or more arguments*/
public void error(String format, Object... arguments);/*** Log an exception (throwable) at the ERROR level with an* accompanying message.** @param msg the message accompanying the exception* @param t   the exception (throwable) to log*/
public void error(String msg, Throwable t);

但是同事坚持log.error("eee{}","11111",e); 这样也能打出异常堆栈,感觉不合常理,本地验证下

    public static void main(String[] args) {try{int i = 1/0;}catch (Exception e){log.error("eee{}","11111",e);}}

输出结果:

15:25:34.462 [main] ERROR com.credithc.inner.InnerApplication - eee11111
java.lang.ArithmeticException: / by zero
    at com.credithc.inner.InnerApplication.main(InnerApplication.java:31)

确实打印出了,异常堆栈, 很是不解,遂debug下

在logback的实现里面有个特殊的处理

会判断下最后一个参数(注意只在最后)是否是Throwable对象,如果是 ,就打印异常堆栈。

log.error打印异常堆栈问题相关推荐

  1. JVM解惑:消失的异常堆栈,log中打印异常堆栈为空

    最近线上发现很多异常没有堆栈信息,只有一句描述,如下: java.lang.NullPointerException: null 排查问题时受到了一些阻碍.然后发现无论是在本地环境还是测试环境,堆栈信 ...

  2. log.error()打印内容区别

    log.error()打印内容 log.error("异常信息:"+e.getMessage) 没有异常信息,没有堆栈信息 log.error("异常信息:"+ ...

  3. 打印异常堆栈_定位生产问题时,异常堆栈莫名丢了,何解?

    今天分享的这个知识有点冷,相信很多 Java 程序员很少遇到,废话不多说,直接进入排查问题的真实讨论现场. 小 猿:有个 NPE 异常,有空帮忙看看是哪里出的? 架构师:我没有看到空指针堆栈啊!? 小 ...

  4. 打印异常堆栈_通过异常堆栈丢失谈即时编译优化

    前言 日照充足会让西瓜更甜,那拥有即时编译优化会让Java程序怎么样?本文会初步介绍JVM的即时编译优化特性,并且通过异常堆栈丢失这一常见的现象来进行举例 即时编译优化 Java程序在运行初期是通过解 ...

  5. 打印异常堆栈_关于日志打印行号的性能案例

    问题描述 上个版本快上线的时候,发现系统整体变慢了.观察页面请求耗时,存在不同程度的性能倒退.观察日志,也没有发现有明显的异常. 分析过程 页面请求后面还有一堆的接口服务,首先需要定界,还好有服务调用 ...

  6. log4j日志打印异常堆栈信息。

    https://www.cnblogs.com/lingyejun/p/9366533.html 五.结论 使用Logger.error(e).Logger.error(e.getMessage()) ...

  7. JAVA如何隐藏异常堆栈_java – 如何在控制台上停止打印异常堆栈跟踪?

    这是我做的这样的战争作为工作. 添加一个过滤器并劫持所有的请求和响应.检查异常并检查类型. /** * Hijacks all the http request and response here. ...

  8. python3 打印异常堆栈信息

    import traceback def fun(a,b):return a/b try:fun(1,0) except Exception as e:traceback.print_exc()#或者 ...

  9. 定位生产问题时,异常堆栈莫名丢了,何解?

    今天分享的这个知识有点冷,相信很多 Java 程序员很少遇到,废话不多说,直接进入排查问题的真实讨论现场. 小   猿:有个 NPE 异常,有空帮忙看看是哪里出的? 架构狮:我没有看到空指针堆栈啊!? ...

  10. java 异常堆栈日志分析_Java 进阶之路:深入解读 Java 异常堆栈丢失原因

    在应用程序的开发和维护中,通常需要借助运行日志来监控和定位问题.其中,在日志中打印异常堆栈信息对于定位问题极为重要,因此,作为一名工程师,对打印异常堆栈应该不陌生.笔者在实践中曾遇到一个奇怪的现象: ...

最新文章

  1. 一步步编写操作系统81 att内嵌汇编语法
  2. 【转载】JS获取浏览器版本信息
  3. 针对vue ui启动项目抛error
  4. 14岁女孩游戏充值6万被发现后自杀,腾讯回应:已完成退款处理
  5. 紫米创始人张峰兼任小米笔记本总经理
  6. vi-vim :删除、撤销、恢复删除、复制删除
  7. 深圳大学二本计算机软件,深圳大学是几本(深圳大学是一本还是二本)
  8. 告别ASP.NET操作EXCEL的烦恼(总结篇)
  9. 从0开始前端开发_设置DIV内容居中
  10. 从JS库的使用者转变成JS的开发者——第一篇 javascript对象
  11. 迪赛智慧数——柱状图(正负条形图):应届生各行业平均薪酬排行
  12. 世界读书日之后聊聊读书
  13. PV-RCNN: Point-Voxel Feature Set Abstraction for 3D Object Detection
  14. matlab中工作空间的作用,MATLAB的工作空间
  15. Sentinel SuperPro/UltraPro Monitor v2.01
  16. 文献解读 | 科学家发现代谢调控促进肿瘤转移新机制
  17. MySql视图原理讲解与使用大全
  18. Java社交商城APP+小程序多功能B2B2C商城源码
  19. 图解机器学习算法(6) | 决策树模型详解(机器学习通关指南·完结)
  20. MP4文件格式详解——文件类型ftyp(转)

热门文章

  1. 【CF633H】Fibonacci-ish II(权值线段树)(莫队)
  2. centos 安装apache2.4
  3. 大学计算机课程日记,大学计算机实习日记.docx
  4. 提高谷歌浏览器下载速度
  5. [办公自动化]目录修改以及插入分页符后行间距自动变宽
  6. git-commit-amend踩坑
  7. 【Python/Pytorch - Bug】-- RuntimeError: ,expected input[16,12,174,145] to have 8 channels,but got 12
  8. 若干个数据首尾相连,构成一个圆环,找到连续的4个数之和最大的一段。 C++
  9. 全微分里dxy是怎么化成xdy+ydx
  10. photoshop文字使用技巧