logging

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2021 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

AllLevels lists all 5 values in order.

View Source
var AllowedPunctuationInFilenames = nonWindowsPunct

Fs provides the filesystem. It can be stubbed for testing.

View Source
var LongBodyThreshold = 100

LongBodyThreshold is the body length threshold beyond which the body will be written to a text file (when the content is text). Otherwise it is written inline in the log.

View Source
var Now = func() time.Time {
	return time.Now().UTC()
}

Now provides the current time. It can be stubbed for testing.

Functions

func IsTextual

func IsTextual(contentType string) bool

IsTextual tests a media type (a.k.a. content type) to determine whether it describes text or binary content.

Types

type Filter added in v0.3.0

type Filter interface {
	Level(*http.Request) Level
}

A Filter determines the logging level, possibly based on each request.

type FilterFunc added in v0.3.0

type FilterFunc func(*http.Request) Level

FilterFunc adapts a function to be a Filter.

func FixedLevel added in v0.3.0

func FixedLevel(level Level) FilterFunc

FixedLevel is a FilterFunc that always return a specified Level.

func (FilterFunc) Level added in v0.3.0

func (f FilterFunc) Level(req *http.Request) Level

type Level

type Level int

Level allows control of the predicate of detail in log messages.

const (
	// Off turns logging off.
	Off Level = iota

	// Discrete log messages contain only a summary of the request and response.
	// No query parameters are printed in order to hide potential personal information.
	Discrete

	// Summary log messages contain only a summary of the request and response,
	// including the full target URL.
	Summary

	// WithHeaders log messages contain a summary and the request/response headers
	WithHeaders

	// WithHeadersAndBodies log messages contain a summary and the request/response headers and bodies
	// Textual bodies are included in the log; for binary content, the size is shown instead.
	WithHeadersAndBodies
)

func (Level) Ordinal added in v0.0.7

func (i Level) Ordinal() int

Ordinal returns the ordinal number of a Level.

func (Level) String added in v0.0.7

func (i Level) String() string

String returns the literal string representation of a Level, which is the same as the const identifier.

type LogContent

type LogContent struct {
	Header http.Header
	Body   []byte
}

type LogItem

type LogItem struct {
	Method     string
	URL        *url.URL
	StatusCode int
	Request    LogContent
	Response   LogContent
	Err        error
	Start      time.Time
	Duration   time.Duration
	Level      Level
}

LogItem records information about one HTTP round-trip.

type Logger

type Logger func(item *LogItem)

Logger is a function that processes log items, usually by writing them to a log file.

func FileLogger added in v0.4.0

func FileLogger(name string) (Logger, error)

FileLogger returns a new Logger writing to a file in dir. The name of the file is provided. The same directory specifies where request and response bodies will be written as files. The current directory is used if this is "." or blank.

func LogWriter

func LogWriter(out io.Writer, dir string) Logger

LogWriter returns a new Logger. The directory dir specifies where request and response bodies will be written as files. The current directory is used if dir is "." or blank.

type VariableFilter added in v0.3.0

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

VariableFilter is a Filter that is controlled by a predicate. This predicate can be altered by any goroutine at any time.

func NewVariableFilter added in v0.3.0

func NewVariableFilter(initial Level) *VariableFilter

NewVariableFilter is a Filter that initially has a fixed level. However, its predicate can be changed later.

func NewVariablePredicate added in v0.3.0

func NewVariablePredicate(initial FilterFunc) *VariableFilter

NewVariablePredicate is a Filter with a predicate that can be changed later.

func (*VariableFilter) Level added in v0.3.0

func (vf *VariableFilter) Level(req *http.Request) Level

func (*VariableFilter) SetLevel added in v0.3.0

func (vf *VariableFilter) SetLevel(newLevel FilterFunc)

SetLevel allows the predicate to be changed. This can be called from any goroutine.

Jump to

Keyboard shortcuts

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