2.9 Logging

► |  | Web Server: HTTP Server

1 | Dispatching Server
2 | Dispatchers
3 | Launching Servers
4 | Web Servers
5 | Internal APIs
6 | Troubleshooting and Tips
| Index

▼ | 2 | Dispatchers

2.1 | General
2.2 | Mapping URLs to Paths
2.3 | Sequencing
2.4 | Timeouts
2.5 | Lifting Procedures
2.6 | Filtering Requests by URL
2.7 | Filtering Requests by Method
2.8 | Procedure Invocation upon Request
2.9 | Logging
2.10 | Basic Logging
2.11 | Password Protection
2.12 | Virtual Hosts
2.13 | Serving Files
2.14 | Serving Servlets
2.15 | Statistics
2.16 | Limiting Requests
2.17 | Wrapping Requests & Responses

On this page:

format-reqresp/ c
paren-format
extended-format
apache-default-format
combined-log-format
log-format/ c
log-format->format
make

top contents ← prev up next →

### 2.9 Logging🔗ℹ

(require web-server/dispatchers/dispatch-logresp)
| package: web-server-lib

The web-server/dispatchers/dispatch-logresp module defines a dispatcher constructor for transparent logging of requests and responses.

> value format-reqresp/c : contract?

Equivalent to (or/c (-> request? string?) (-> request? response? string?)).

> value paren-format : format-reqresp/c

Formats a request and a response by:

> (format
> "~s\n"
> (list 'from (request-client-ip req)
> 'to (request-host-ip req)
> 'for (url->string (request-uri req))
> 'at (date->string
> (seconds->date (current-seconds)) #t)
> 'code (response-code resp)))

> value extended-format : format-reqresp/c

Formats a request and a response by:

> (format
> "~s\n"
> `((client-ip ,(request-client-ip req))
> (host-ip ,(request-host-ip req))
> (referer
> ,(let ([R (headers-assq*
> #"Referer"
> (request-headers/raw req))])
> (if R
> (header-value R)
> #f)))
> (uri ,(url->string (request-uri req)))
> (time ,(current-seconds))
> (code ,(response-code resp))))

> value apache-default-format : format-reqresp/c

Formats a request and a response like Apache’s default. However, Apache’s default includes information about the size of the object returned to the client, which this function does not have access to, so it defaults the last field to -.

> value combined-log-format : format-reqresp/c

Formats a request and a response to approximate the Combined Log Format. As this function does not have access to the size of the object returned to the client, it defaults the field to -.

> value log-format/c : contract?

Equivalent to (symbols 'parenthesized-default 'extended 'apache-default 'combined).

> procedure (log-format->format id) → format-reqresp/c
> id : log-format/c

Maps 'parenthesized-default to paren-format, 'extended to extended-format, 'apache-default to apache-default-format, and 'combined to combined-log-format

> > procedure
> > (make | [ | #:format format |  |  |  |
> > |  | #:log-path log-path] |  |  |  |
> > |  | dispatcher) |  | → |  | dispatcher/c
> format : (or/c log-format/c format-reqresp/c) = paren-format
> log-path : (or/c path-string? output-port?) = "log"
> dispatcher : dispatcher/c

If dispatcher is successfully dispatched, logs requests and responses (without the body information) to log-path, which can be either a filepath or an output-port?, using format to format the requests and responses (or just requests if format only accepts one argument). If format is a symbol, a log formatter will be tacitly made using log-format->format.

Added in version 1.12 of package web-server-lib.

top contents ← prev up next →