Log all requests, not only ones that hit backup target, fix comments to be docstring friendly.
This commit is contained in:
@@ -78,6 +78,8 @@ func NewServer(configPath string) (*serverWrapper, error) { //nolint: revive
|
|||||||
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
|
|
||||||
|
log.Infof("Access denied from %s to %s (no username or password given)", r.RemoteAddr, r.RequestURI)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +90,8 @@ func NewServer(configPath string) (*serverWrapper, error) { //nolint: revive
|
|||||||
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
|
||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||||
|
|
||||||
|
log.Infof("Access denied from %s to %s (username and/or password incorrect)", r.RemoteAddr, r.RequestURI)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,8 +277,8 @@ func getCompressionAlgorithm(requestedExt string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// serverWrapper wraps http.Server to intercept and classify errors.
|
|
||||||
type (
|
type (
|
||||||
|
// serverWrapper wraps [http.Server] to intercept and classify errors.
|
||||||
serverWrapper struct {
|
serverWrapper struct {
|
||||||
*http.Server
|
*http.Server
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ var (
|
|||||||
Log *os.File
|
Log *os.File
|
||||||
)
|
)
|
||||||
|
|
||||||
// slogWriter implements io.Writer to redirect standard log to slog.
|
// slogWriter implements [io.Writer] to redirect standard log to slog.
|
||||||
type (
|
type (
|
||||||
slogWriter struct {
|
slogWriter struct {
|
||||||
handler slog.Handler
|
handler slog.Handler
|
||||||
@@ -145,7 +145,7 @@ func DebugLogger() *log.Logger {
|
|||||||
return log.New(&slogWriter{handler: handler}, "", 0)
|
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,
|
// TLS-related errors are logged at debug level, while other errors (handler issues,
|
||||||
// unexpected behavior) are logged at warn level.
|
// unexpected behavior) are logged at warn level.
|
||||||
func (w *slogWriter) Write(p []byte) (int, error) {
|
func (w *slogWriter) Write(p []byte) (int, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user