twitter / finatra

Fast, testable, Scala services built on TwitterServer and Finagle
https://twitter.github.io/finatra/
Apache License 2.0
2.27k stars 406 forks source link

No access log for 404 responses #510

Closed gaspaio closed 4 years ago

gaspaio commented 4 years ago

When the Finatra router is handed a request that doesn't match the registered routes, a 404 response in sent that seems to bypasses the accessLog filter. No log is written and I can't find a way to catch these events and log them as responses to a request.

Expected behavior

Write an access log using the same access log filter that logs 2xx responses. A 404 is an HTTP response like any other and should probably be logged at such, by default.

Actual behavior

No log is writen, response bypasses the accesslog filter

Steps to reproduce the behavior

Sent a request to a finatra server that doesn't match a registered route. You'll get a 404 response, but no log (at the info level, there is a debug log from the router).

cacoco commented 4 years ago

@gaspaio this is somewhat intentional. The idea was not to log every garbage request to your service if you are being DDOS'd for example. Filters will only be executed when a route is found and dispatched to. In this case, the routing service did not find a route to dispatch to thus the filter chain (including the access logging filter) is not executed. A way around this is to set up the filter to be executed before routing matching, e.g., (beforeRouting=true).

https://twitter.github.io/finatra/user-guide/http/filters.html#global-filters

gaspaio commented 4 years ago

ok, that's a very good design decision. Thanks for the quick reply and the ref to how to address my particular needs. Have a good day ! :-) Closing.