github.com/chenbh/concourse/v6@v6.4.2/atc/wrappa/logger_handler.go (about)

     1  package wrappa
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	"code.cloudfoundry.org/lager"
     8  )
     9  
    10  type LoggerHandler struct {
    11  	Logger  lager.Logger
    12  	Handler http.Handler
    13  }
    14  
    15  func (handler LoggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    16  	logger := handler.Logger.Session("http-request", lager.Data{
    17  		"request-path": r.URL.Path,
    18  	})
    19  	ctx := context.WithValue(r.Context(), "logger", logger)
    20  	handler.Handler.ServeHTTP(w, r.WithContext(ctx))
    21  }