Skip to content

Add response logging #54

Closed
Closed

Description

@flux77

Suppose I have a web application:

#lang racket
(require web-server/servlet-env)

; Some web app code here ...

;; Start the web server.
(serve/servlet request-handler
                       #:log-file "/dev/stdout")

When I start the web server and access the web app through the browser, the logs appear like this:

127.0.0.1 - - [25/Dec/2018:12:34:56 +0000] "GET /servlets/standalone.rkt HTTP/1.1" - -
127.0.0.1 - - [25/Dec/2018:12:34:56 +0000] "GET /favicon.ico HTTP/1.1" - -

The HTTP response code is missing from the logs, making it difficult to know when any of the web pages result in 500, 403, 404, etc.

Would it be possible to implement request + response logging? Request + response logs are more useful in tracking past errors. For example:

127.0.0.1 - - [25/Dec/2018:12:34:56 +0000] "GET /servlets/standalone.rkt HTTP/1.1"  401 152 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"
127.0.0.1 - - [25/Dec/2018:12:34:56 +0000] "GET /favicon.ico HTTP/1.1" 404 152 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

(Originally asked on Stack Overflow: https://stackoverflow.com/questions/53911162/)

Activity

  1. jeapostrophe commented on Jan 29, 2019

    @jeapostrophe
    Contributor

    First, the existing request logging system is fully parameterized for you to make custom log formats. You can use the #:log-format argument and browse the existing options in the web-server/dispatchers/dispatch-log module.

    Second, the way to do to this is to wrap your response creation function in something that intercepts and logs. The server is set up so all responses come from (-> request response) functions, so if you are currently using f change it to (log&return req (f req)) where log&return makes the log you want and then returns it up. I am happy to merge this into the main repo if it is clean. It should be quite straight-forward to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions