improve & document logging for unix sockets

This commit is contained in:
Johann150 2023-03-17 19:29:18 +01:00
parent f266de8a16
commit 965f804146
No known key found for this signature in database
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 18 additions and 10 deletions

View file

@ -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>]
```
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.

View file

@ -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 {