logger.error用途转载
原创使用SLF4J打印包含占位符的日志(place holder){},通常不会异常,打印如下:
[html] view plain copy
logger.info("InvestmentFacadeImpl queryInvestmentInfo: investmentListResponse is {}", investmentListResponse);
{} 是占位符,则打印结果为
[html] view plain copy
InvestmentFacadeImpl queryInvestmentInfo: investmentListResponse is ****
如果异常,我应该如何打印?
错误演示:
[html] view plain copy
logger.error("CrowdFundingAssetServiceImpl insert throws exception is {}", e.getMessage());
事实上,我们可以看看error() 方法的源代码将知道正确的打印方法:
[html] view plain copy
/*
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);
对于例外情况,占位符不是必需的,也不是必需的。e.getMessage(),可以直接打印
e.getMessage()只能打印短信息,如果需要堆栈信息,则需要添加 e
[html] view plain copy
logger.error("FinancingManualFacadeImpl.addFinancingProduct failed! ", e);
作者:sayok_why
来源:CSDN
原文:https://blog.csdn.net/sayoko06/article/details/79315348
版权声明:本文为博主原创文章,转载请附上博客链接!
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
itfan123



