Log all requests, not only ones that hit backup target, fix comments to be docstring friendly.

This commit is contained in:
eleksir
2026-04-04 14:44:48 +03:00
parent e449fb78c9
commit fd8612cfc6
2 changed files with 7 additions and 3 deletions

View File

@@ -78,6 +78,8 @@ func NewServer(configPath string) (*serverWrapper, error) { //nolint: revive
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
http.Error(w, "Unauthorized", http.StatusUnauthorized)
log.Infof("Access denied from %s to %s (no username or password given)", r.RemoteAddr, r.RequestURI)
return
}
@@ -88,6 +90,8 @@ func NewServer(configPath string) (*serverWrapper, error) { //nolint: revive
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
http.Error(w, "Unauthorized", http.StatusUnauthorized)
log.Infof("Access denied from %s to %s (username and/or password incorrect)", r.RemoteAddr, r.RequestURI)
return
}
@@ -273,8 +277,8 @@ func getCompressionAlgorithm(requestedExt string) string {
}
}
// serverWrapper wraps http.Server to intercept and classify errors.
type (
// serverWrapper wraps [http.Server] to intercept and classify errors.
serverWrapper struct {
*http.Server
}

View File

@@ -16,7 +16,7 @@ var (
Log *os.File
)
// slogWriter implements io.Writer to redirect standard log to slog.
// slogWriter implements [io.Writer] to redirect standard log to slog.
type (
slogWriter struct {
handler slog.Handler
@@ -145,7 +145,7 @@ func DebugLogger() *log.Logger {
return log.New(&slogWriter{handler: handler}, "", 0)
}
// Write implements io.Writer. It differentiates TLS/SSL errors from other errors.
// Write implements [io.Writer]. It differentiates TLS/SSL errors from other errors.
// TLS-related errors are logged at debug level, while other errors (handler issues,
// unexpected behavior) are logged at warn level.
func (w *slogWriter) Write(p []byte) (int, error) {