httplog

package
v0.5.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// MessageKey is the key used to store the log message.
	MessageKey = "message"
	// RequestKey is the key used to keep the request if enabled.
	RequestKey = "request"
	// ResponseKey is the key used to keep the response if enabled.
	ResponseKey = "response"
	// ErrorKey is the key used to store an error.
	ErrorKey = "error"
)

Variables

This section is empty.

Functions

func Middleware

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

Middleware 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 Option added in v0.0.11

type Option func(o *options)

Option is the type used to modify logger options.

func WithRedactor added in v0.0.11

func WithRedactor(fn RedactorFunc) Option

WithRedactor is an option that adds a new redactor to a httplog.

type RawResponseLogger

type RawResponseLogger interface {
	ResponseLogger
	Buffer() *bytes.Buffer
	Response() []byte
}

RawResponseLogger 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 RedactorFunc added in v0.0.11

type RedactorFunc func(w http.ResponseWriter, r *http.Request)

RedactorFunc is a function that redacts the HTTP request or response logged.

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{}
	WithField(key string, value interface{})
	WithFields(map[string]interface{})
	Field(key string) (interface{}, bool)
	Request() (*Request, 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