requestlog

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ReceivedTime      time.Time
	RequestMethod     string
	RequestURL        string
	RequestHeaderSize int64
	RequestBodySize   int64
	UserAgent         string
	Referer           string
	Proto             string

	RemoteIP string
	ServerIP string

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

Entry records information about a completed HTTP request.

type Handler

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

A Handler emits request information to a Logger.

func NewHandler

func NewHandler(log Logger, h http.Handler) *Handler

NewHandler returns a handler that emits information to log and calls h.ServeHTTP.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP calls its underlying handler's ServeHTTP method, then calls Log after the handler returns.

ServeHTTP will always consume the request body up to the first error, even if the underlying handler does not.

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 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