Documentation
¶
Overview ¶
Simple package to log http requests and response info Meant for use with net/http package Built on top of go.uber.org/zap
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithLogging ¶
WithLogging wraps http.Handler with logging middleware It logs request method, path, remote address, response status and latency in nanoseconds See ExampleWithLogging for usage
Example ¶
// Create a zap test logger logger, _ := zap.NewProduction() defer logger.Sync() http.HandleFunc("/api/data", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusCreated) w.Write([]byte("Success!")) }) // Wrap the test handler with our logging middleware http.ListenAndServe(":8080", http_logger.WithLogging(http.DefaultServeMux, logger))
Output:
Types ¶
type ResponseWriterWithLogging ¶
type ResponseWriterWithLogging struct { http.ResponseWriter // contains filtered or unexported fields }
func (*ResponseWriterWithLogging) Write ¶
func (w *ResponseWriterWithLogging) Write(b []byte) (int, error)
func (*ResponseWriterWithLogging) WriteHeader ¶
func (w *ResponseWriterWithLogging) WriteHeader(status int)
WriteHeader wraps original http.ResponseWriter WriteHeader method to store status code
Click to show internal directories.
Click to hide internal directories.