go-httplog: github.com/lassik/go-httplog Index | Files

package httplog

import "github.com/lassik/go-httplog"


Package Files

formats.go handler.go statwriter.go types.go util.go

func AppendQuoted Uses

func AppendQuoted(buf []byte, s string) []byte

AppendQuoted appends a quoted version of string s to buf.

func CombinedLogLine Uses

func CombinedLogLine(r LogRequest) []byte

CombinedLogLine returns a log entry in Apache Combined Log Format.

See http://httpd.apache.org/docs/2.2/logs.html#combined

Always sets the ident field of the log to -

func CommonLogLine Uses

func CommonLogLine(r LogRequest) []byte

CommonLogLine returns a log entry in Apache Common Log Format (CLF).

See http://httpd.apache.org/docs/2.2/logs.html#common

Always sets the ident field of the log to -

func LogHandler Uses

func LogHandler(handler http.Handler, logger Logger) logHandler

LogHandler makes a http.Handler (middleware for the Go HTTP server). For each HTTP request, it calls the user-supplied handler. At the end of the request, it additionally calls the user-supplied logger to log the request.

The logger gets a LogRequest. Usually you'll want to call one of the log formatting functions in this package or roll your own log formatter. Then write the resulting log entry somewhere.

func ParseHostAndURI Uses

func ParseHostAndURI(r *http.Request) (string, string)

ParseHostAndURI gets the host and URI from a HTTP request. It tries some tricks if they don't have normal values.

func ParseUser Uses

func ParseUser(r *http.Request) string

ParseUser gets the username from a HTTP request, or - if none.

type LogRequest Uses

type LogRequest struct {
    StartTime time.Time
    EndTime   time.Time
    User      string
    Host      string
    Method    string
    URI       string
    Proto     string
    Referer   string
    UserAgent string
    Size      int
    Status    int

LogRequest holds all the logging information pertaining to a single HTTP request. Log formatters turn this struct into a log entry in the desired format. This struct holds the information in a pre-parsed format to make it as easy as possible to write log formatters.

type Logger Uses

type Logger func(r LogRequest)

Logger is any user-supplied function to process one LogRequest.

Package httplog imports 5 packages (graph). Updated 2019-03-11. Refresh now. Tools for package owners.