github.com/uvalib/orcid-access-ws@v0.0.0-20250612130209-7d062dbabf9d/orcidaccessws/handler_logger.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/uvalib/orcid-access-ws/orcidaccessws/logger"
     6  	"net/http"
     7  	"time"
     8  )
     9  
    10  // HandlerLogger -- middleware handler
    11  func HandlerLogger(inner http.Handler, name string) http.Handler {
    12  
    13  	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    14  
    15  		start := time.Now()
    16  
    17  		inner.ServeHTTP(w, r)
    18  
    19  		logger.Log(fmt.Sprintf(
    20  			"%s %s (%s) -> method %s, time %s",
    21  			r.Method,
    22  			r.RequestURI,
    23  			r.RemoteAddr,
    24  			name,
    25  			time.Since(start),
    26  		))
    27  	})
    28  }
    29  
    30  //
    31  // end of file
    32  //