Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AllLevels = []Level{ Off, Discrete, Summary, WithHeaders, WithHeadersAndBodies, }
AllLevels lists all 5 values in order.
var ItemFileName = func(item *LogItem) string { return fmt.Sprintf("%s_%s_%s%s", file.FilenameTimestamp(item.Start), item.Method, file.Hostname(item.Request.Header), file.UrlToFilename(item.URL.Path)) }
ItemFileName builds a filename that distinctively represents the request that raised the LogItem.
This is pluggable with alternative implementations. The default implementation concatenates the timestamp, the method, the hostname, and the URL. No extension is added -
var Now = func() time.Time { return time.Now().UTC() }
Now provides the current time. It can be stubbed for testing.
Functions ¶
This section is empty.
Types ¶
type Filter ¶ added in v0.3.0
A Filter determines the logging level, possibly based on each request.
type FilterFunc ¶ added in v0.3.0
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.
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) Int ¶ added in v0.9.2
Int returns the int value, which is not necessarily the same as the ordinal. This facilitates polymorphism (see enum.IntEnum).
func (Level) IsValid ¶ added in v0.9.2
IsValid determines whether a Level is one of the defined constants.
type LogContent ¶
func (LogContent) ContentType ¶ added in v0.9.2
func (lc LogContent) ContentType() string
ContentType gets the "Content-Type" header and returns the first part, i.e. excluding all parameters.
func (LogContent) FileExtension ¶ added in v0.9.2
func (lc LogContent) FileExtension() string
FileExtension gets normal file extension for the content type represented by this content.
func (LogContent) IsTextual ¶ added in v0.9.2
func (lc LogContent) IsTextual() bool
IsTextual determines whether this content is normally consiudered to be textual. If the content is binary, the result is false.
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 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.