java - 如何在 Spring MVC 中记录传入请求
问题描述
我有一个这样的 JSON 请求正文
{
"3DSecure":{
"paRes":"xxxxxxxxxxxxxxxxxxxxxxx"
}
}
我开发了端点来记录该请求。
@RequestMapping(value = "/logging/requests", method = RequestMethod.POST)
@ResponseBody
public String loggingIncomingRequest(@RequestBody AxiPayCargilsRequest request,
HttpServletRequest servletRequest,
ServiceContext serviceContext){
log.info("!--REQUEST START--!"+request);
log.info("");
return null;
}
如何记录这个请求任何人都可以从对象创建的层面帮助我谢谢。
解决方案
首先,在 pom.xml 中添加以下依赖项
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2</version>
</dependency>
然后,在所有需要记录的类中初始化记录器,例如,
private final static Logger logger = LogManager.getFormatterLogger(YourClassName.class);
现在,您可以像这样使用记录器,
logger.info("Your Logging info");
推荐阅读
- apache - 将客户端 IP 更改为 API 请求的代理 IP
- java - 从迭代器转移到每个
- ms-access - 我可以同时安装两个版本的 Microsoft Access(2007 和 2013),以便我仍然可以打开 .adp 文件吗?
- identityserver4 - 无效的redirect_uri,即使它们相同
- sql - SQL根据第二个表中的搜索条件从第一个表中检索数据
- django - Django django_suit:如何创建两级菜单?
- magento - Magento 2 不显示文本样本值
- linux - 将命令行参数传递给 qml
- php - SELECT with JOIN -> 我想将这些表与 JOIN 结合起来
- node.js - 我想升级 node-loopback 应用程序中的所有 npm 包