Skip to content

Commit

Permalink
Extended logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasavelin committed Jul 3, 2024
1 parent 543edb2 commit ab02723
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package server
import (
"context"
"errors"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/protobuf/encoding/protojson"
"log"
"net"
"net/http"
"strconv"

"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"

Expand Down Expand Up @@ -62,14 +62,14 @@ func NewServer(config *ServerConfig) *Server {

// Serve both the gRPC server and the http/json proxy on the same port
httpServer := &http.Server{
Handler: h2c.NewHandler(
Handler: LoggingMiddleware(h2c.NewHandler(
config.HttpAndGrpcHandlerFunc(
grpcMux,
grpcServer,
config.HandlerOptions,
),
&http2.Server{},
),
)),
}

return &Server{
Expand Down Expand Up @@ -101,3 +101,15 @@ func (s *Server) Shutdown(ctx context.Context) error {
}
return nil
}

// LoggingMiddleware logs the incoming request URL
func LoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(
w http.ResponseWriter,
r *http.Request,
) {
// Log the complete request URL
log.Printf("Request URL: %s", r.URL.String())
next.ServeHTTP(w, r)
})
}

0 comments on commit ab02723

Please sign in to comment.