Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Set TLS Handshake logs to debug
This adds a logDebug, which if set true, prints debug-level logs.

The logs from the http.Server are quite noisy from random internet scans, so
set them to debug.

Since we still want to see errors from our own getCertificate, add a logging
wrapper for it at the warn level.
  • Loading branch information
mcpherrinm committed Mar 23, 2026
commit 6ff36a86159a5679a131d8cef66705934f110582
10 changes: 10 additions & 0 deletions certs/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ func isACME(info *tls.ClientHelloInfo) bool {

// GetCertificate implements the interface required by tls.Config
func (c *CertManager) GetCertificate(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
cert, err := c.get(info)
if err != nil {
slog.Warn("getting certificate", slog.String("error", err.Error()))
}

return cert, err
}

// get is the core of GetCertificate, which wraps this for observability
func (c *CertManager) get(info *tls.ClientHelloInfo) (*tls.Certificate, error) { //nolint:funcorder
sni := info.ServerName

c.mu.Lock()
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type Config struct {

// TextTemplate overrides the default plain text webpage
TextTemplate string

// LogDebug enables debug level logs when set to true
Comment thread
pgporada marked this conversation as resolved.
LogDebug bool
}

// Site configures a particular site.
Expand Down
3 changes: 2 additions & 1 deletion integration/test-certs-site-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"directory": "https://pebble:14000/dir",
"termsOfServiceAgreed": true
},
"dataDir": "/data"
"dataDir": "/data",
"logDebug": true
}
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
)

func run(args []string) error {
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, nil)))
logLevel := &slog.LevelVar{}
logLevel.Set(slog.LevelInfo)
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel})))

fs := flag.NewFlagSet(args[0], flag.ExitOnError)
cfgPath := fs.String("config", "config.json", "path to json config file")
Expand All @@ -40,6 +42,10 @@ func run(args []string) error {
return fmt.Errorf("loading config: %w", err)
}

if cfg.LogDebug {
logLevel.Set(slog.LevelDebug)
}

store, err := storage.New(cfg.DataDir)
if err != nil {
return fmt.Errorf("creating storage: %w", err)
Expand Down
7 changes: 5 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ func Run(ctx context.Context, cfg *config.Config, getCert GetCertificateFunc) er
return err
}

logger := slog.NewLogLogger(slog.Default().Handler(), slog.LevelDebug)

srv := http.Server{
Addr: cfg.ListenAddr,
Handler: handler,
Addr: cfg.ListenAddr,
Handler: handler,
ErrorLog: logger,

Comment thread
mcpherrinm marked this conversation as resolved.
IdleTimeout: timeout,
ReadHeaderTimeout: timeout,
Expand Down