feat(cli): add verbose logging option for CLI commands
Some checks failed
CI / build-and-test (push) Failing after -32m43s

* Introduced a new flag `--verbose` to enable detailed logging.
* Implemented logging for connection events in SSE and stdio commands.
* Added a utility function to handle verbose logging.
This commit is contained in:
2026-04-21 22:24:57 +02:00
parent 979afc909e
commit 9a9fa4f384
16 changed files with 317 additions and 87 deletions

View File

@@ -3,12 +3,13 @@ package observability
import (
"context"
"log/slog"
"net"
"net/http"
"runtime/debug"
"time"
"github.com/google/uuid"
"git.warky.dev/wdevs/amcs/internal/requestip"
)
type contextKey string
@@ -67,7 +68,7 @@ func AccessLog(log *slog.Logger) func(http.Handler) http.Handler {
slog.String("path", r.URL.Path),
slog.Int("status", recorder.status),
slog.Duration("duration", time.Since(started)),
slog.String("remote_addr", stripPort(r.RemoteAddr)),
slog.String("remote_addr", requestip.FromRequest(r)),
)
})
}
@@ -100,11 +101,3 @@ func (s *statusRecorder) WriteHeader(statusCode int) {
s.status = statusCode
s.ResponseWriter.WriteHeader(statusCode)
}
func stripPort(remote string) string {
host, _, err := net.SplitHostPort(remote)
if err != nil {
return remote
}
return host
}