From 965f804146143120c5d2a681cfdbfea84e7d99f4 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Fri, 17 Mar 2023 19:29:18 +0100 Subject: [PATCH] improve & document logging for unix sockets --- README.md | 13 ++++++++++--- src/main.rs | 15 ++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3b52a5c..348a4d6 100644 --- 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: ``` : "" ""[ 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:[] - "" ""[ error:] +``` -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. +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. 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 index 5466701..6afaa92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -458,13 +458,14 @@ impl RequestHandle { stream: UnixStream, metadata: Arc>, ) -> Result { - let log_line = match stream.local_addr() { - Ok(a) => match a.as_pathname() { - Some(p) => format!("{} -", p.display()), - None => " -".to_string(), - }, - Err(_) => " -".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 {