accesslog

package
v2.0.0-alpha1+incompat... Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StartUTC is the map key used for the time at which request processing started.
	StartUTC = "StartUTC"
	// StartLocal is the map key used for the local time at which request processing started.
	StartLocal = "StartLocal"
	// Duration is the map key used for the total time taken by processing the response, including the origin server's time but
	// not the log writing time.
	Duration = "Duration"

	// RouterName is the map key used for the name of the Traefik router.
	RouterName = "RouterName"
	// ServiceName is the map key used for the name of the Traefik backend.
	ServiceName = "ServiceName"
	// ServiceURL is the map key used for the URL of the Traefik backend.
	ServiceURL = "ServiceURL"
	// ServiceAddr is the map key used for the IP:port of the Traefik backend (extracted from BackendURL)
	ServiceAddr = "ServiceAddr"

	// ClientAddr is the map key used for the remote address in its original form (usually IP:port).
	ClientAddr = "ClientAddr"
	// ClientHost is the map key used for the remote IP address from which the client request was received.
	ClientHost = "ClientHost"
	// ClientPort is the map key used for the remote TCP port from which the client request was received.
	ClientPort = "ClientPort"
	// ClientUsername is the map key used for the username provided in the URL, if present.
	ClientUsername = "ClientUsername"
	// RequestAddr is the map key used for the HTTP Host header (usually IP:port). This is treated as not a header by the Go API.
	RequestAddr = "RequestAddr"
	// RequestHost is the map key used for the HTTP Host server name (not including port).
	RequestHost = "RequestHost"
	// RequestPort is the map key used for the TCP port from the HTTP Host.
	RequestPort = "RequestPort"
	// RequestMethod is the map key used for the HTTP method.
	RequestMethod = "RequestMethod"
	// RequestPath is the map key used for the HTTP request URI, not including the scheme, host or port.
	RequestPath = "RequestPath"
	// RequestProtocol is the map key used for the version of HTTP requested.
	RequestProtocol = "RequestProtocol"
	// RequestContentSize is the map key used for the number of bytes in the request entity (a.k.a. body) sent by the client.
	RequestContentSize = "RequestContentSize"
	// RequestRefererHeader is the Referer header in the request
	RequestRefererHeader = "request_Referer"
	// RequestUserAgentHeader is the User-Agent header in the request
	RequestUserAgentHeader = "request_User-Agent"
	// OriginDuration is the map key used for the time taken by the origin server ('upstream') to return its response.
	OriginDuration = "OriginDuration"
	// OriginContentSize is the map key used for the content length specified by the origin server, or 0 if unspecified.
	OriginContentSize = "OriginContentSize"
	// OriginStatus is the map key used for the HTTP status code returned by the origin server.
	// If the request was handled by this Traefik instance (e.g. with a redirect), then this value will be absent.
	OriginStatus = "OriginStatus"
	// DownstreamStatus is the map key used for the HTTP status code returned to the client.
	DownstreamStatus = "DownstreamStatus"
	// DownstreamContentSize is the map key used for the number of bytes in the response entity returned to the client.
	// This is in addition to the "Content-Length" header, which may be present in the origin response.
	DownstreamContentSize = "DownstreamContentSize"
	// RequestCount is the map key used for the number of requests received since the Traefik instance started.
	RequestCount = "RequestCount"
	// GzipRatio is the map key used for the response body compression ratio achieved.
	GzipRatio = "GzipRatio"
	// Overhead is the map key used for the processing time overhead caused by Traefik.
	Overhead = "Overhead"
	// RetryAttempts is the map key used for the amount of attempts the request was retried.
	RetryAttempts = "RetryAttempts"
)
View Source
const (
	// DataTableKey is the key within the request context used to store the Log Data Table.
	DataTableKey key = "LogDataTable"

	// CommonFormat is the common logging format (CLF).
	CommonFormat string = "common"

	// JSONFormat is the JSON logging format.
	JSONFormat string = "json"
)

Variables

This section is empty.

Functions

func AddOriginFields

func AddOriginFields(rw http.ResponseWriter, req *http.Request, next http.Handler, data *LogData)

AddOriginFields add origin fields

func AddServiceFields

func AddServiceFields(rw http.ResponseWriter, req *http.Request, next http.Handler, data *LogData)

AddServiceFields add service fields

func NewFieldHandler

func NewFieldHandler(next http.Handler, name string, value string, applyFn FieldApply) http.Handler

NewFieldHandler creates a Field handler.

func ParseAccessLog

func ParseAccessLog(data string) (map[string]string, error)

ParseAccessLog parse line of access log and return a map with each fields

func WrapHandler

func WrapHandler(handler *Handler) alice.Constructor

WrapHandler Wraps access log handler into an Alice Constructor.

Types

type CommonLogFormatter

type CommonLogFormatter struct{}

CommonLogFormatter provides formatting in the Traefik common log format.

func (*CommonLogFormatter) Format

func (f *CommonLogFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats the log entry in the Traefik common log format.

type CoreLogData

type CoreLogData map[string]interface{}

CoreLogData holds the fields computed from the request/response.

type FieldApply

type FieldApply func(rw http.ResponseWriter, r *http.Request, next http.Handler, data *LogData)

FieldApply function hook to add data in accesslog

type FieldHandler

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

FieldHandler sends a new field to the logger.

func (*FieldHandler) ServeHTTP

func (f *FieldHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Handler

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

Handler will write each request and its response to the access log.

func NewHandler

func NewHandler(config *types.AccessLog) (*Handler, error)

NewHandler creates a new Handler.

func (*Handler) Close

func (h *Handler) Close() error

Close closes the Logger (i.e. the file, drain logHandlerChan, etc).

func (*Handler) Rotate

func (h *Handler) Rotate() error

Rotate closes and reopens the log file to allow for rotation by an external source.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.Handler)

type LogData

type LogData struct {
	Core               CoreLogData
	Request            http.Header
	OriginResponse     http.Header
	DownstreamResponse http.Header
}

LogData is the data captured by the middleware so that it can be logged.

func GetLogData

func GetLogData(req *http.Request) *LogData

GetLogData gets the request context object that contains logging data. This creates data as the request passes through the middleware chain.

type SaveRetries

type SaveRetries struct{}

SaveRetries is an implementation of RetryListener that stores RetryAttempts in the LogDataTable.

func (*SaveRetries) Retried

func (s *SaveRetries) Retried(req *http.Request, attempt int)

Retried implements the RetryListener interface and will be called for each retry that happens.

Jump to

Keyboard shortcuts

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