Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only log status in ServletRequestHandledEvent #27595

Closed
darioseidl opened this issue Oct 22, 2021 · 3 comments
Closed

Only log status in ServletRequestHandledEvent #27595

darioseidl opened this issue Oct 22, 2021 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@darioseidl
Copy link

darioseidl commented Oct 22, 2021

The ServletRequestHandledEvent is very convenient for logging handled HTTP servlet requests.

For example in Spring Boot Web (Kotlin):

/**
 * An [EventListener] for logging handled HTTP requests.
 */
@Component
class HttpRequestEventListener {

    private val log = KotlinLogging.logger {}

    @EventListener
    fun handle(event: RequestHandledEvent) {
        log.trace { "HTTP request handled: ${event.description}" }
    }
}

... this logs all requests as:

HTTP request handled: url=[/example]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcherServlet]; session=[null]; user=[null]; time=[115ms]; status=[OK]

However, this is a bit confusing at first, as this will print "status=OK" even when the HTTP response status code is not 200. The status comes from the RequestHandledEvent here, which prints "OK" if there was no exception.

In this pull request the HTTP status code was added to ServletRequestHandledEvent, but it is not included in the description.

Would it make sense to include it in the description too?

To return, for example, this

url=[/example]; client=[127.0.0.1]; method=[GET]; servlet=[dispatcherServlet]; session=[null]; user=[null]; time=[115ms]; status=[OK]; statusCode=[404]

Of course, it's easy enough to adjust the logging in our event handler, but including the statusCode seems like a generally useful thing to me.

If this would be a welcome addition, I can provide a pull request.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 22, 2021
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Oct 23, 2021
@snicoll
Copy link
Member

snicoll commented Sep 25, 2023

I agree that the OK status if there isn't a failure is a bit confusing. I am not sure we'd go as far as adding the description to it. Adding to team attention to get more feedback from the team.

@rstoyanchev
Copy link
Contributor

I think the base class should not log "status=[OK|Failed:...]" since it doesn't know the status and it's misleading to log OK which implies 200 but the actual status could be even in the 4xx-5xx range. The base class should focus on logging "failure:..." if there is one. The ServletRequestHandledEvent subclass on the other hand should log the actual status.

@snicoll snicoll changed the title Include HTTP status code in ServletRequestHandledEvent.desciption Only log status in ServletRequestHandledEvent Sep 29, 2023
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 29, 2023
@snicoll snicoll added this to the 6.x Backlog milestone Sep 29, 2023
@snicoll
Copy link
Member

snicoll commented Sep 29, 2023

Sounds good, I've requalified this issue in that direction.

@snicoll snicoll modified the milestones: 6.x Backlog, 6.1.3 Jan 4, 2024
@snicoll snicoll self-assigned this Jan 4, 2024
@snicoll snicoll closed this as completed in 2784f60 Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants