Skip to content

Commit 6acc686

Browse files
frenzzyjoseluisq
andauthored
docs: one per-request log line with the response status (v3) (#17)
* docs: one per-request log line with the response status (v3) * docs: sync per-request logging with the merged code (v3) --------- Co-authored-by: Jose Quintana <joseluisquintana20@gmail.com>
1 parent e27ec52 commit 6acc686

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎src/v3/configuration/cli.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Options:
105105
--access-log-format <ACCESS_LOG_FORMAT>
106106
Custom access log format string using %{token} syntax. When set, replaces the default request logging with a configurable format that includes response data. Tokens: method, uri, status, bytes, duration, remote_addr, x_real_ip, forwarded_for, host, user_agent, referer, timestamp, version. x_real_ip and forwarded_for are logged only for requests from --trusted-proxies, if set. Example: '%{remote_addr} "%{method} %{uri}" %{status} %{bytes}' [env: SERVER_ACCESS_LOG_FORMAT=] [default: ""]
107107
--log-remote-address [<LOG_REMOTE_ADDRESS>]
108-
Log incoming requests information along with its remote address if available using the `info` log level [env: SERVER_LOG_REMOTE_ADDRESS=] [default: false] [possible values: true, false]
108+
Log the remote address of each request, if available [env: SERVER_LOG_REMOTE_ADDRESS=] [default: false] [possible values: true, false]
109109
--log-x-real-ip [<LOG_X_REAL_IP>]
110110
Log the X-Real-IP header for remote IP information [env: SERVER_LOG_X_REAL_IP=] [default: false] [possible values: true, false]
111111
--log-forwarded-for [<LOG_FORWARDED_FOR>]

‎src/v3/configuration/env.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Custom access log format using the `%{token}` syntax. When set, SWS logs one lin
181181

182182
## SERVER_LOG_REMOTE_ADDRESS
183183

184-
Log incoming requests information along with its remote address if available using the `info` log level. Default `false`.
184+
Log the remote address of each request, if available. Default `false`.
185185

186186
## SERVER_LOG_X_REAL_IP
187187

‎src/v3/features/logging.md‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static-web-server -p 8787 -d ./public/ -g info --log-format pretty
5858
```log
5959
2026-05-29T23:44:04.703047+02:00 INFO static_web_server::server: starting Static Web Server name="static-web-server" version="2.42.0"
6060
2026-05-29T23:44:04.704137+02:00 INFO static_web_server::compression: auto compression enabled=true formats=deflate,gzip,brotli,zstd compression_level=Default
61-
2026-05-29T23:44:05.724579+02:00 INFO static_web_server::log_addr: incoming request method=GET uri=/
61+
2026-05-29T23:44:05.724579+02:00 INFO static_web_server::log_addr: response method=GET uri=/ status=200
6262
```
6363

6464
## Log Date-Timestamp
@@ -90,20 +90,21 @@ static-web-server -p 8788 -d ./public/ -g trace --log-format pretty --log-with-a
9090

9191
## Per-request logging
9292

93-
When the level is `info` or lower, SWS logs each request with the `incoming request` message. Requests to the [health endpoints](./health-endpoint.md) (`/livez` and `/readyz`) are logged at `debug` level instead, to avoid noise from frequent probes.
93+
When the level is `info` or lower, SWS logs one line per request with the `response` message, once the response body is sent or aborted. The line carries the request method, the URI as sent by the client (before [URL Rewrites](./url-rewrites)) and the response `status`, including for responses that end the request early, such as redirects or `405 Method Not Allowed`. Requests to the [health endpoints](./health-endpoint.md) (`/livez` and `/readyz`) are logged at `debug` level instead, to avoid noise from frequent probes.
9494

9595
```json
9696
{
9797
"timestamp": "2026-05-29T23:43:47.151533+02:00",
9898
"level": "INFO",
99-
"message": "incoming request",
99+
"message": "response",
100100
"method": "GET",
101101
"uri": "/",
102+
"status": 200,
102103
"target": "static_web_server::log_addr"
103104
}
104105
```
105106

106-
The `remote_addr`, `x_real_ip` and `real_remote_ip` fields are added when the corresponding logging options are enabled and a value is available. Fields without a value are omitted.
107+
No line is logged when SWS fails to build a response. The `remote_addr`, `x_real_ip` and `real_remote_ip` fields are added when the corresponding logging options are enabled and a value is available. Fields without a value are omitted.
107108

108109
## Log Remote Addresses
109110

@@ -117,7 +118,7 @@ static-web-server -a "0.0.0.0" -p 8080 -d docker/public/ -g info --log-remote-ad
117118

118119
```json
119120
{"timestamp":"2026-05-29T23:43:47.071681+02:00","level":"INFO","message":"log requests with remote IP addresses","enabled":true,"target":"static_web_server::log_addr"}
120-
{"timestamp":"2026-05-29T23:43:47.151533+02:00","level":"INFO","message":"incoming request","method":"GET","uri":"/","remote_addr":"192.168.1.126","target":"static_web_server::log_addr"}
121+
{"timestamp":"2026-05-29T23:43:47.151533+02:00","level":"INFO","message":"response","method":"GET","uri":"/","status":200,"remote_addr":"192.168.1.126","target":"static_web_server::log_addr"}
121122
```
122123

123124
## Logging Client IP from X-Real-IP header
@@ -130,9 +131,10 @@ Enable logging of the `X-Real-IP` header with the `--log-x-real-ip` option or th
130131
{
131132
"timestamp": "2026-05-29T23:43:47.151533+02:00",
132133
"level": "INFO",
133-
"message": "incoming request",
134+
"message": "response",
134135
"method": "GET",
135136
"uri": "/",
137+
"status": 200,
136138
"x_real_ip": "203.0.113.195",
137139
"target": "static_web_server::log_addr"
138140
}
@@ -178,9 +180,10 @@ The request log includes the `real_remote_ip` field:
178180
{
179181
"timestamp": "2026-05-29T23:43:47.151533+02:00",
180182
"level": "INFO",
181-
"message": "incoming request",
183+
"message": "response",
182184
"method": "GET",
183185
"uri": "/",
186+
"status": 200,
184187
"real_remote_ip": "203.0.113.195",
185188
"target": "static_web_server::log_addr"
186189
}
@@ -200,9 +203,10 @@ the log omits `real_remote_ip`:
200203
{
201204
"timestamp": "2026-05-29T23:43:47.151533+02:00",
202205
"level": "INFO",
203-
"message": "incoming request",
206+
"message": "response",
204207
"method": "GET",
205208
"uri": "/",
209+
"status": 200,
206210
"target": "static_web_server::log_addr"
207211
}
208212
```
@@ -223,9 +227,10 @@ curl "http://[::1]:8080" --header "X-Forwarded-For: <iframe src=//malware.attack
223227
{
224228
"timestamp": "2026-05-29T23:43:47.151533+02:00",
225229
"level": "INFO",
226-
"message": "incoming request",
230+
"message": "response",
227231
"method": "GET",
228232
"uri": "/",
233+
"status": 200,
229234
"target": "static_web_server::log_addr"
230235
}
231236
```
@@ -234,7 +239,7 @@ curl "http://[::1]:8080" --header "X-Forwarded-For: <iframe src=//malware.attack
234239

235240
**`SWS`** can write one access log line per request in a format you define, for example the nginx or NCSA combined format. The line is written when the response body is finished, so it carries the status code, the number of body bytes sent and the duration of the whole transfer.
236241

237-
This feature is disabled by default. Set a format with the `--access-log-format` option, the equivalent [SERVER_ACCESS_LOG_FORMAT](./../configuration/env#server_access_log_format) env or the `access-log-format` key under `[general]` in the [TOML file](./../configuration/file). When a format is set, it replaces the `incoming request` line described in [Per-request logging](#per-request-logging).
242+
This feature is disabled by default. Set a format with the `--access-log-format` option, the equivalent [SERVER_ACCESS_LOG_FORMAT](./../configuration/env#server_access_log_format) env or the `access-log-format` key under `[general]` in the [TOML file](./../configuration/file). When a format is set, it replaces the `response` line described in [Per-request logging](#per-request-logging).
238243

239244
```sh
240245
static-web-server -p 8787 -d ./public/ -g info \

0 commit comments

Comments
 (0)