在Spring应用程序中在容器启动时记录宁静的端点 [英] Log restful endpoints on container startup in a Spring application

查看:119
本文介绍了在Spring应用程序中在容器启动时记录宁静的端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring应用程序,该应用程序通过Controller类中的@RequestMapping注释公开了宁静的端点.

I've a Spring application that expose restful endpoints through @RequestMapping annotation in Controller classes.

我希望在服务器启动时将控制台登录到应用程序所有控制器的所有端点.

I wish that were logged into the console, at server startup, all the endpoints of all the application's controller.

我使用tomcat服务器和log4j进行日志记录.

I use a tomcat server and log4j for logging.

谢谢.

推荐答案

对于使用spring-boot的用户:

在最新的 spring-boot 版本(自v2.1起)中,他们更改了映射默认日志级别(如发行说明

In the latest spring-boot release (since v2.1), they changed the mapping default log level (as specified in the Release Notes here).

将以下属性之一添加到 application.properties 文件:

Add one of the following properties to application.properties file:

  • logging.level.web=TRACE
  • logging.level.org.springframework.web=TRACE
  • logging.level.web=TRACE
  • logging.level.org.springframework.web=TRACE

示例控制台输出:

2018-12-12 11:16:51.793 TRACE 11868 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping
    c.n.c.MyController:
    {POST /users}: addUser(User)
    {DELETE /users}: deleteUser(User)
    {PUT /users}: updateUser(User)
    {GET /users/{id}}: getUserById(String)
    {GET /users}: getUsers()
    {GET /users_static}: getUsersStaticList()
2018-12-12 11:16:51.795 TRACE 11868 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping
    o.s.b.a.w.s.e.BasicErrorController:
    { /error}: error(HttpServletRequest)
    { /error, produces [text/html]}: errorHtml(HttpServletRequest,HttpServletResponse)

这篇关于在Spring应用程序中在容器启动时记录宁静的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆