Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

java - Log restful endpoints on container startup in a Spring application

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.

I use a tomcat server and log4j for logging.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For those who use spring-boot:

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

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

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

Sample Console Output:

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...