index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2022-05-28 20:22:49.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2022-05-28 20:22:49.0 +00:00:00
commit
2d71de67f4990a3808a938f207b314bf17a3de56 [patch]
tree
359a71fb1b29ced5a275907bf03f5861dfe550aa
parent
fa531a0745962fde31908fab422462146e5c2142
download
2d71de67f4990a3808a938f207b314bf17a3de56.tar.gz

docs: log remote address section [skip ci]



Diff

 docs/content/configuration/command-line-arguments.md |  9 +++--
 docs/content/configuration/environment-variables.md  |  3 ++-
 docs/content/features/logging.md                     | 35 +++++++++++++++++++++-
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/docs/content/configuration/command-line-arguments.md b/docs/content/configuration/command-line-arguments.md
index 0be9bcc..a494823 100644
--- a/docs/content/configuration/command-line-arguments.md
+++ b/docs/content/configuration/command-line-arguments.md
@@ -66,18 +66,21 @@ OPTIONS:
            Enable HTTP/2 with TLS support [env: SERVER_HTTP2_TLS=]  [default: false]

        --http2-tls-cert <http2-tls-cert>
            Specify the file path to read the certificate [env: SERVER_HTTP2_TLS_CERT=]  [default: ]
            Specify the file path to read the certificate [env: SERVER_HTTP2_TLS_CERT=]

        --http2-tls-key <http2-tls-key>
            Specify the file path to read the private key [env: SERVER_HTTP2_TLS_KEY=]  [default: ]
            Specify the file path to read the private key [env: SERVER_HTTP2_TLS_KEY=]

    -g, --log-level <log-level>
            Specify a logging level in lower case. Values: error, warn, info, debug or trace [env: SERVER_LOG_LEVEL=]
            [default: error]
        --log-remote-address <log-remote-address>
            Log incoming requests information along with its remote address if available using the `info` log level
            [env: SERVER_LOG_REMOTE_ADDRESS=]  [default: false]
        --page-fallback <page-fallback>
            HTML file path that is used for GET requests when the requested path doesn't exist. The fallback page is
            served with a 200 status code, useful when using client routers. If the path is not specified or simply
            doesn't exist then this feature will not be active [env: SERVER_FALLBACK_PAGE=]  [default: ]
            doesn't exist then this feature will not be active [env: SERVER_FALLBACK_PAGE=]
        --page404 <page404>
            HTML file path for 404 errors. If the path is not specified or simply doesn't exist then the server will use
            a generic HTML error message [env: SERVER_ERROR_PAGE_404=]  [default: ./public/404.html]
diff --git a/docs/content/configuration/environment-variables.md b/docs/content/configuration/environment-variables.md
index 04dbe09..2b8d7f3 100644
--- a/docs/content/configuration/environment-variables.md
+++ b/docs/content/configuration/environment-variables.md
@@ -27,6 +27,9 @@ Defines a grace period in seconds after a `SIGTERM` signal is caught which will 
### SERVER_LOG_LEVEL
Specify a logging level in lower case. Possible values are `error`, `warn`, `info`, `debug` or `trace`. Default `error`.

### SERVER_LOG_REMOTE_ADDRESS
Log incoming requests information along with its Remote Address (IP) if available using the `info` log level.

### SERVER_ERROR_PAGE_404
HTML file path for 404 errors. If path is not specified or simply don't exists then server will use a generic HTML error message. Default `./public/404.html`.

diff --git a/docs/content/features/logging.md b/docs/content/features/logging.md
index b4dfa88..9db2872 100644
--- a/docs/content/features/logging.md
+++ b/docs/content/features/logging.md
@@ -12,3 +12,38 @@ static-web-server \
    --root ./my-public-dir \
    --log-level "trace"
```

## Log Remote Addresses

SWS provides **Remote Address (IP)** logging for every request via an `INFO` log level.

This feature is disabled by default and can be enabled by the boolean `--log-remote-address` option or the equivalent [SERVER_LOG_REMOTE_ADDRESS]./../configuration/environment-variables.md#server_log_remote_address env.

If the feature is enabled then log entries for requests will contain a `remote_addr` section with the remote address (IP) value. Otherwise it will be empty.

Log entry example:

```log
2022-05-23T22:24:50.519540Z  INFO static_web_server::handler: incoming request: method=GET uri=/ remote_addr=192.168.1.126:57625
```

Below an example of how to enable Remote Address (IP) logging. Note the last two entries.

```sh
static-web-server -a "0.0.0.0" -p 8080 -d docker/public/ -g info --log-remote-address=true
# 2022-05-23T22:24:44.523057Z  INFO static_web_server::logger: logging level: info
# 2022-05-23T22:24:44.523856Z  INFO static_web_server::server: server bound to TCP socket 0.0.0.0:8080
# 2022-05-23T22:24:44.523962Z  INFO static_web_server::server: runtime worker threads: 4
# 2022-05-23T22:24:44.523989Z  INFO static_web_server::server: security headers: enabled=false
# 2022-05-23T22:24:44.524006Z  INFO static_web_server::server: auto compression: enabled=true
# 2022-05-23T22:24:44.524061Z  INFO static_web_server::server: directory listing: enabled=false
# 2022-05-23T22:24:44.524097Z  INFO static_web_server::server: directory listing order code: 6
# 2022-05-23T22:24:44.524133Z  INFO static_web_server::server: cache control headers: enabled=true
# 2022-05-23T22:24:44.524191Z  INFO static_web_server::server: basic authentication: enabled=false
# 2022-05-23T22:24:44.524210Z  INFO static_web_server::server: grace period before graceful shutdown: 0s
# 2022-05-23T22:24:44.524527Z  INFO Server::start_server{addr_str="0.0.0.0:8080" threads=4}: static_web_server::server: close time.busy=0.00ns time.idle=10.6µs
# 2022-05-23T22:24:44.524585Z  INFO static_web_server::server: listening on http://0.0.0.0:8080
# 2022-05-23T22:24:44.524614Z  INFO static_web_server::server: press ctrl+c to shut down the server
# 2022-05-23T22:24:50.519540Z  INFO static_web_server::handler: incoming request: method=GET uri=/ remote_addr=192.168.1.126:57625
# 2022-05-23T22:25:26.516841Z  INFO static_web_server::handler: incoming request: method=GET uri=/favicon.ico remote_addr=192.168.1.126:57625
```