requestlog

package
v0.0.0-...-eb33cdb Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package requestlog provides an http.Handler that logs information about requests.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWriterNotPusher   error = errors.New("underlying ResponseWriter is not a Pusher")
	ErrWriterNotHijacker error = errors.New("underlying ResponseWriter is not a Hijacker")
)
View Source
var DefaultFilteredHeaders = []string{"Authorization", "Cookie"}

Functions

func New

func New(logger Logger) func(next http.Handler) http.Handler

New returns a middleware that emits information to log and calls h.ServeHTTP.

Types

type Entry

type Entry struct {
	// Request is the http request that has been completed.
	//
	// This request's Body is always nil, regardless of the actual request body.
	Request *http.Request

	ReceivedTime    time.Time
	RequestBodySize int64

	Status             int
	ResponseHeaderSize int64
	ResponseBodySize   int64
	Latency            time.Duration
	TraceID            trace.TraceID
	SpanID             trace.SpanID

	// Deprecated. This value is available by evaluating Request.Referer().
	Referer string
	// Deprecated. This value is available directing in Request.Proto.
	Proto string
	// Deprecated. This value is available directly in Request.Method.
	RequestMethod string
	// Deprecated. This value is available directly in Request.URL.
	RequestURL string
	// Deprecated. This value is available by evaluating Request.Header.
	RequestHeaderSize int64
	// Deprecated. This value is available by evaluating Request.Header.
	UserAgent string
	// Deprecated. This value is available by evaluating Request.RemoteAddr..
	RemoteIP string
	// Deprecated. This value is available by evaluating reading the
	// http.LocalAddrContextKey value from the context returned by Request.Context().
	ServerIP string
}

Entry records information about a completed HTTP request.

type Logger

type Logger interface {
	Log(*Entry)
}

Logger wraps the Log method. Log must be safe to call from multiple goroutines. Log must not hold onto an Entry after it returns.

type NCSALogger

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

An NCSALogger writes log entries to an io.Writer in the Combined Log Format.

Details at http://httpd.apache.org/docs/current/logs.html#combined

func NewNCSALogger

func NewNCSALogger(w io.Writer, onErr func(error)) *NCSALogger

NewNCSALogger returns a new logger that writes to w. A nil onErr is treated the same as func(error) {}.

func (*NCSALogger) Log

func (l *NCSALogger) Log(ent *Entry)

Log writes an entry line to its writer. Multiple concurrent calls will produce sequential writes to its writer.

type ReqLogger

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

func NewReqLogger

func NewReqLogger(logger log.Logger, filteredHeaders []string) *ReqLogger

func (*ReqLogger) Log

func (s *ReqLogger) Log(ent *Entry)

type StackdriverLogger

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

A StackdriverLogger writes log entries in the Stackdriver forward JSON format. The record's fields are suitable for consumption by Stackdriver Logging.

func NewStackdriverLogger

func NewStackdriverLogger(w io.Writer, onErr func(error)) *StackdriverLogger

NewStackdriverLogger returns a new logger that writes to w. A nil onErr is treated the same as func(error) {}.

func (*StackdriverLogger) Log

func (l *StackdriverLogger) Log(ent *Entry)

Log writes a record to its writer. Multiple concurrent calls will produce sequential writes to its writer.

Jump to

Keyboard shortcuts

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