events

package module
v0.0.0-...-451ac38 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: MIT Imports: 11 Imported by: 0

README

events

HTTP event logger and middleware

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FieldDuration       = "duration"
	FieldErrorCause     = "errorCause"
	FieldErrorStack     = "errorStack"
	FieldHTTPMethod     = "httpMethod"
	FieldHTTPRemoteAddr = "httpRemoteAddr"
	FieldHTTPRespLen    = "httpRespLen"
	FieldHTTPRespStatus = "httpRespStatus"
	FieldHTTPSourceIP   = "httpSourceIp"
	FieldHTTPURI        = "httpUri"
	FieldHTTPUserAgent  = "httpUserAgent"
	FieldProtocol       = "protocol"
	FieldRequestID      = "requestId"
)

Functions

func ContextLogger

func ContextLogger(ctx context.Context) *logrus.Entry

func GetCause

func GetCause(err error) (error, bool)

GetCause unwraps the error and returns the original error if it is not the same as the passed error.

func NewEventContext

func NewEventContext(ctx context.Context, event *Event) context.Context

func RequestIP

func RequestIP(r *http.Request, trustForwardedFor bool) string

func RequestLogger

func RequestLogger(r *http.Request) *logrus.Entry

func SetRequestError

func SetRequestError(r *http.Request, err error)

func SetRequestField

func SetRequestField(r *http.Request, key string, value interface{})

func UnwrapAll

func UnwrapAll(err error) error

Types

type Event

type Event struct {
	// contains filtered or unexported fields
}

func EventFromContext

func EventFromContext(ctx context.Context) *Event

func NewEvent

func NewEvent(logger *logrus.Entry) *Event

func (*Event) GetField

func (e *Event) GetField(key string) interface{}

func (*Event) Logger

func (e *Event) Logger() *logrus.Entry

func (*Event) SetError

func (e *Event) SetError(err error)

func (*Event) SetField

func (e *Event) SetField(key string, value interface{})

type HTTPMiddleware

type HTTPMiddleware struct {
	BuildEvent         func(r *http.Request, e *Event)
	TrustForwardedFor  bool
	RequestIDHeaderKey string
	RequestLogMessage  string
	EventLogMessage    string
	LogRequest         func(e *Event)
	LogEvent           func(e *Event)
	// contains filtered or unexported fields
}

func NewHTTPMiddleware

func NewHTTPMiddleware(next http.Handler, logger *logrus.Entry) *HTTPMiddleware

func (*HTTPMiddleware) ServeHTTP

func (m *HTTPMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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