gocloud.dev: gocloud.dev/server/requestlog Index | Files

package requestlog

import "gocloud.dev/server/requestlog"

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

Index

Package Files

ncsa.go requestlog.go stackdriver.go

type Entry Uses

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 Uses

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

A Handler emits request information to a Logger.

func NewHandler Uses

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

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

func (*Handler) ServeHTTP Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

Package requestlog imports 11 packages (graph) and is imported by 9 packages. Updated 2019-07-09. Refresh now. Tools for package owners.