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

Add response logging #54

Closed
flux77 opened this issue Jan 29, 2019 · 1 comment · Fixed by #119
Closed

Add response logging #54

flux77 opened this issue Jan 29, 2019 · 1 comment · Fixed by #119

Comments

@flux77
Copy link

flux77 commented Jan 29, 2019

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/)

@jeapostrophe
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants