4

I use the following log level logging.level.org.springframework.web= ERROR and wish also to see in my log 404 error (with full URL) that is generated when requested URL cannot be matched to any controller. What is the best way for this?

Bizon4ik
  • 2,604
  • 4
  • 20
  • 46
  • Include more information, code snippets, screenshots, log trace. which could be helpful in finding a solution. – Vikram Palakurthi Mar 29 '18 at 21:51
  • @VikramPalakurthi I created a new spring-boot app without any controller. Put above mention logging level in `application.property` and start the app. Then send some request to this app and obtained 404 error in response, however, there is nothing in the application log. What should I do to find 404 error in log (change log level to `DEBUG` is not an option)? – Bizon4ik Mar 29 '18 at 22:13
  • So when there is no controller in place and you are trying to access the url which gave you a 404 error. This sounds right to me. Implement a base controller and then try to access it. What you created is just a simple application without any access points, try to complete it by adding a controller and methods which handle requests and send responses (view or json) for example. – Vikram Palakurthi Mar 29 '18 at 22:19
  • And, if you want to see the logs you need to update the log config for tomcat, if that's what you are using. – Vikram Palakurthi Mar 29 '18 at 22:20
  • use this reference to enable logs https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html – Vikram Palakurthi Mar 29 '18 at 22:21
  • Possible duplicate of [Spring Boot: How can I set the logging level with application.properties?](https://stackoverflow.com/questions/20485059/spring-boot-how-can-i-set-the-logging-level-with-application-properties) – Vikram Palakurthi Mar 29 '18 at 22:24
  • [404 Exception not handled in Spring ControllerAdvice](https://stackoverflow.com/questions/54116245/404-exception-not-handled-in-spring-controlleradvice) might help – Danish ALI Mar 07 '23 at 02:53

1 Answers1

0

I did a bit of experimentation and turn outs that for now you have to add following to the properties

spring.mvc.throw-exception-if-no-handler-found=true
spring.web.resources.add-mappings=false

then even with no logging configuration you will get logs which look something like:

2023-03-07T03:35:24.323Z WARN 283306 --- [nio-8080-exec-1] o.s.web.servlet.PageNotFound : No mapping for GET /bad 2023-03-07T03:35:24.327Z WARN 283306 --- [nio-8080-exec-1] o.s.web.servlet.PageNotFound : No endpoint GET /bad. 2023-03-07T03:35:24.329Z WARN 283306 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.servlet.NoHandlerFoundException: No endpoint GET /bad.]

Danish ALI
  • 65
  • 1
  • 9