eia-api-go/pkg/eia/eia_logging.go

25 lines
512 B
Go
Raw Normal View History

2024-11-16 19:02:46 +00:00
package eia
import (
"context"
"net/http"
"time"
"github.com/rs/zerolog"
eiaapi "gitea.libretechconsulting.com/50W/eia-api-go/api"
)
func newLoggingMiddleware(logger *zerolog.Logger, level zerolog.Level) eiaapi.RequestEditorFn {
return func(_ context.Context, req *http.Request) error {
logger.WithLevel(level).
Str("method", req.Method).
Str("host", req.URL.Host).
Str("path", req.URL.Path).
Str("query", req.Form.Encode()).
Time("timestamp", time.Now()).
Send()
return nil
}
}