agate

Simple gemini server for static files
git clone https://github.com/mbrubeck/agate.git
Log | Files | Refs | README

commit 965f804146143120c5d2a681cfdbfea84e7d99f4
parent f266de8a169e1487dd8ca2aa9b5efdedb33ce75e
Author: Johann150 <johann.galle@protonmail.com>
Date:   Fri, 17 Mar 2023 19:29:18 +0100

improve & document logging for unix sockets

Diffstat:
MREADME.md | 13++++++++++---
Msrc/main.rs | 15++++++++-------
2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md @@ -182,13 +182,20 @@ The files for a certificate/key pair have to be named `cert.der` and `key.der` r ## Logging -All requests will be logged using this format: +All requests via TCP sockets will be logged using this format: ``` <local ip>:<local port> <remote ip or dash> "<request>" <response status> "<response meta>"[ error:<error>] ``` -The "error:" part will only be logged if an error occurred. This should only be used for informative purposes as the status code should provide the information that an error occurred. If the error consisted in the connection not being established (e.g. because of TLS errors), the status code `00` will be used. +All requests via Unix sockets will be logged using this format: +``` +unix:[<unix socket name>] - "<request>" <response status> "<response meta>"[ error:<error>] +``` + +Square brackets indicate optional parts. + +The "error:" part will only be logged if an error occurred. This should only be used for informative purposes as the status code should provide the information that an error occurred. If the error consisted in the connection not being established (e.g. because of TLS errors), special status codes listed below may be used. -By default, Agate will not log the remote IP addresses because that might be an issue because IPs are considered private data under the EU's GDPR. To enable logging of IP addresses, you can use the `--log-ip` option. Note that in this case some error conditions might still force Agate to log a dash instead of an IP address. +By default, Agate will not log the remote IP addresses because that might be an issue because IPs are considered private data under the EU's GDPR. To enable logging of IP addresses, you can use the `--log-ip` option. Note that in this case some error conditions might still force Agate to log a dash instead of an IP address. IP addresses can also not be logged for connections via Unix sockets. There are some lines apart from these that might occur in logs depending on the selected log level. For example the initial "Listening on..." line or information about listing a particular directory. diff --git a/src/main.rs b/src/main.rs @@ -458,13 +458,14 @@ impl RequestHandle<UnixStream> { stream: UnixStream, metadata: Arc<Mutex<FileOptions>>, ) -> Result<Self, String> { - let log_line = match stream.local_addr() { - Ok(a) => match a.as_pathname() { - Some(p) => format!("{} -", p.display()), - None => "<unnamed socket> -".to_string(), - }, - Err(_) => "<unnamed socket> -".to_string(), - }; + let log_line = format!( + "unix:{} -", + stream + .local_addr() + .ok() + .and_then(|addr| Some(addr.as_pathname()?.to_string_lossy().into_owned())) + .unwrap_or_default() + ); match TLS.accept(stream).await { Ok(stream) => Ok(Self {