Add structured logging with log/slog

Replace fmt.Printf logging calls with slog.Info/slog.Error for structured
JSON output to stderr. Add internal/log package to initialize the default
slog handler from the config log level. Fix .gitignore to only ignore the
binary at the repo root, not the cmd/eng-pad-server directory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 20:52:22 -07:00
parent c5469c6bdf
commit a9e6ca022e
6 changed files with 145 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"html/template"
"io/fs"
"log/slog"
"net/http"
"time"
@@ -85,10 +86,10 @@ func Start(cfg Config) (*http.Server, error) {
Certificates: []tls.Certificate{tlsCert},
MinVersion: tls.VersionTLS13,
}
fmt.Printf("Web UI listening on %s (TLS)\n", cfg.Addr)
slog.Info("web UI started", "addr", cfg.Addr, "tls", true)
go func() { _ = srv.ListenAndServeTLS("", "") }()
} else {
fmt.Printf("Web UI listening on %s\n", cfg.Addr)
slog.Info("web UI started", "addr", cfg.Addr, "tls", false)
go func() { _ = srv.ListenAndServe() }()
}