httplog

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2020 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(logger *logging.Logger, next http.Handler) http.Handler

NewLoggerHandler returns the given http.Handler with the logger integrated.

Types

type Headers added in v0.0.3

type Headers http.Header

Headers represents key-value pairs in the HTTP headers.

func (Headers) Get added in v0.0.3

func (h Headers) Get(key string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "".

func (Headers) MarshalLogObject added in v0.0.3

func (h Headers) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject adds the headers in the log.

func (Headers) Values added in v0.0.3

func (h Headers) Values(key string) []string

Values returns all values associated with the given key.

type LoggerHandler

type LoggerHandler struct {
	*logging.Logger
	// contains filtered or unexported fields
}

LoggerHandler creates a logger handler

func (*LoggerHandler) ServeHTTP

func (l *LoggerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler and call to the handler to log with a custom http.ResponseWriter that records the response code and the number of bytes sent.

type RawResponseLogger

type RawResponseLogger interface {
	ResponseLogger
	Response() []byte
}

ResponseLogger defines an interface that a responseWrite can implement to support the capture of the status code, the number of bytes written and extra log entry fields.

func NewRawResponseLogger

func NewRawResponseLogger(w http.ResponseWriter) RawResponseLogger

NewRawResponseLogger wraps the given response writer with the methods to capture the status code, the bytes written, and methods to add new log entries. It won't wrap the response writer if it's already a RawResponseLogger.

type Request added in v0.0.3

type Request struct {
	Headers Headers
	Body    []byte
}

Request represents an HTTP request, it implements a zapcore.ObjectMarshaller on it.

func NewRequest added in v0.0.3

func NewRequest(r *http.Request) (*Request, error)

NewRequest creates a Request object from an http.Request.

func (*Request) MarshalLogObject added in v0.0.3

func (r *Request) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject adds the properties of the request in the log.

type Response added in v0.0.3

type Response struct {
	Headers Headers
	Body    []byte
}

Response represents an HTTP response, it implements a zapcore.ObjectMarshaller on it.

func (*Response) MarshalLogObject added in v0.0.3

func (r *Response) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject adds the properties of the response in the log.

type ResponseLogger

type ResponseLogger interface {
	http.ResponseWriter
	Size() int
	StatusCode() int
	Fields() map[string]interface{}
	WithFields(map[string]interface{})
	Field(key string) (interface{}, bool)
}

ResponseLogger defines an interface that a responseWrite can implement to support the capture of the status code, the number of bytes written and extra log entry fields.

func NewResponseLogger

func NewResponseLogger(w http.ResponseWriter) ResponseLogger

NewResponseLogger wraps the given response writer with methods to capture the status code, the number of bytes written, and methods to add new log entries. It won't wrap the response writer if it's already a ResponseLogger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL