Documentation ¶
Index ¶
- Variables
- func Accept(r *http.Request) bool
- func CalcLengths(buckets []*stack.Bucket, fullPath bool) (int, int)
- func ColorWrite(w io.Writer, useColor bool, color []byte, s string, args ...interface{})
- func ColorWriteTtyCheck(w io.Writer, useColor bool, color []byte, s string, args ...interface{})
- func GetRealIP(r *http.Request) string
- func Logger(next http.Handler) http.Handler
- func LoggerPrintRequestMessage(...)
- func LoggerPrintResponseMessage(...)
- func NoCache(next http.Handler) http.Handler
- func PostLimit(maxPostSize int64, failedHandler ...PostLimitFailedHandler) func(next http.Handler) http.Handler
- func Recoverer(f ...PanicFormatter) func(next http.Handler) http.Handler
- func RequestLogger(f LogFormatter) func(next http.Handler) http.Handler
- func SetNoCache(w http.ResponseWriter, r *http.Request) http.ResponseWriter
- func StackWriteToConsole(out io.Writer, p *StackPalette, buckets []*stack.Bucket, ...) error
- func WithLogEntry(r *http.Request, entry LogEntry) *http.Request
- type ColorWriterFunc
- type DefaultLogAndPanicFormatter
- type Extensions
- func (this Extensions) Copy() (m Extensions)
- func (this *Extensions) PtrUpdate(news ...Extensions) *Extensions
- func (this *Extensions) PtrUpdateStrings(values ...string) *Extensions
- func (this Extensions) Update(news ...Extensions) Extensions
- func (this Extensions) UpdateStrings(values ...string) Extensions
- type LogAndPanicFormatter
- type LogEntry
- type LogFormatter
- type LoggerInterface
- type PanicEntry
- type PanicFormatter
- type PostLimitFailedHandler
- type StackPalette
Constants ¶
This section is empty.
Variables ¶
var ( // LogEntryCtxKey is the context.Context key to store the request log entry. LogEntryCtxKey = &contextKey{"LogEntry"} // PanicEntryCtxKey is the context.Context key to store the request panic entry. PanicEntryCtxKey = &contextKey{"PanicEntry"} // DefaultLoggerExtensionsIgnore is the default request extensions to ignores DefaultLoggerExtensionsIgnore = StringsToExtensions("css", "js", "jpg", "png", "gif", "ico", "ttf", "woff2", "svg", "svgz") DefaultRequestLogFormatter = &DefaultLogAndPanicFormatter{ Logger: log.New(os.Stdout, "", log.LstdFlags), PanicLogger: log.New(os.Stderr, "", log.LstdFlags), IgnoreExtensions: DefaultLoggerExtensionsIgnore, } // DefaultLogger is called by the Logger middleware handler to log each request. // Its made a package-level variable so that it can be reconfigured for custom // logging configurations. DefaultLogger = RequestLogger(DefaultRequestLogFormatter) )
var DefaultPostLimitFailedHandler = PostLimitFailedHandler(func(w http.ResponseWriter, r *http.Request) { http.Error(w, "max post size exceeded", http.StatusBadRequest) })
var ParseForm = post_limit.ParseForm
Functions ¶
func CalcLengths ¶
CalcLengths returns the maximum length of the source lines and package names.
func ColorWrite ¶
ColorWrite
func ColorWriteTtyCheck ¶
colorWriteTtyCheck
func Logger ¶
Logger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return. When standard output is a TTY, Logger will print in color, otherwise it will print in black and white. Logger prints a request BID if one is provided.
Alternatively, look at https://github.com/pressly/lg and the `lg.RequestLogger` middleware pkg.
func NoCache ¶
NoCache is a simple piece of middleware that sets a number of HTTP headers to prevent a router (or subrouter) from being cached by an upstream proxy and/or client.
As per http://wiki.nginx.org/HttpProxyModule - NoCache sets:
Expires: Thu, 01 Jan 1970 00:00:00 UTC Cache-Control: no-cache, private, max-age=0 X-Accel-Expires: 0 Pragma: no-cache (for HTTP/1.0 proxies/clients)
func Recoverer ¶
func Recoverer(f ...PanicFormatter) func(next http.Handler) http.Handler
Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a HTTP 500 (Internal Server Error) status if possible. Recoverer prints a request BID if one is provided.
func RequestLogger ¶
func RequestLogger(f LogFormatter) func(next http.Handler) http.Handler
RequestLogger returns a logger handler using a custom LogFormatter.
func SetNoCache ¶
func SetNoCache(w http.ResponseWriter, r *http.Request) http.ResponseWriter
func StackWriteToConsole ¶
Types ¶
type ColorWriterFunc ¶
type DefaultLogAndPanicFormatter ¶
type DefaultLogAndPanicFormatter struct {
Logger, PanicLogger LoggerInterface
NoColor bool
IgnoreExtensions Extensions
TruncateUri int
NoColorTtyCheck bool
}
DefaultLogAndPanicFormatter is a simple logger that implements a LogFormatter.
func (*DefaultLogAndPanicFormatter) Accept ¶
func (l *DefaultLogAndPanicFormatter) Accept(r *http.Request) bool
func (*DefaultLogAndPanicFormatter) NewLogEntry ¶
func (l *DefaultLogAndPanicFormatter) NewLogEntry(r *http.Request) LogEntry
NewLogEntry creates a new LogEntry for the request.
func (*DefaultLogAndPanicFormatter) NewPanicEntry ¶
func (l *DefaultLogAndPanicFormatter) NewPanicEntry(r *http.Request) PanicEntry
NewPanicEntry creates a new LogEntry for the request panic.
type Extensions ¶
func StringsToExtensions ¶
func StringsToExtensions(values ...string) (m Extensions)
func (Extensions) Copy ¶
func (this Extensions) Copy() (m Extensions)
func (*Extensions) PtrUpdate ¶
func (this *Extensions) PtrUpdate(news ...Extensions) *Extensions
func (*Extensions) PtrUpdateStrings ¶
func (this *Extensions) PtrUpdateStrings(values ...string) *Extensions
func (Extensions) Update ¶
func (this Extensions) Update(news ...Extensions) Extensions
func (Extensions) UpdateStrings ¶
func (this Extensions) UpdateStrings(values ...string) Extensions
type LogAndPanicFormatter ¶
type LogAndPanicFormatter interface { LogFormatter PanicFormatter }
type LogEntry ¶
type LogEntry interface { Write(status, bytes int, elapsed time.Duration) WithLogger(logger LoggerInterface) LogEntry }
LogEntry records the final log when a request completes. See defaultLogEntry for an example implementation.
func GetLogEntry ¶
GetLogEntry returns the in-context LogEntry for a request.
func NewLogEntry ¶
type LogFormatter ¶
LogFormatter initiates the beginning of a new LogEntry per request. See DefaultLogAndPanicFormatter for an example implementation.
type LoggerInterface ¶
type LoggerInterface interface {
Print(v ...interface{})
}
LoggerInterface accepts printing to stdlib logger or compatible logger.
type PanicEntry ¶
type PanicEntry interface { Write(v interface{}, stack []byte) WithLogger(logger LoggerInterface) PanicEntry }
PanicEntry records the final log when a request failed. See defaultPanicEntry for an example implementation.
func GetPanicEntry ¶
func GetPanicEntry(r *http.Request) PanicEntry
GetLogEntry returns the in-context LogEntry for a request.
func NewPanicEntry ¶
func NewPanicEntry(r *http.Request) PanicEntry
type PanicFormatter ¶
type PanicFormatter interface {
NewPanicEntry(r *http.Request) PanicEntry
}
PanicFormatter initiates the beginning of a new PanicEntry per request. See DefaultLogAndPanicFormatter for an example implementation.
type PostLimitFailedHandler ¶
type PostLimitFailedHandler = http.HandlerFunc
type StackPalette ¶
type StackPalette struct { EOLReset string // Routine header. RoutineFirst string // The first routine printed. Routine string // Following routines. CreatedBy string // Call line. Package string SrcFile string FuncStdLib string FuncStdLibExported string FuncMain string FuncOther string FuncOtherExported string Arguments string }
StackPalette defines the color used.
An empty object StackPalette{} can be used to disable coloring.
func (*StackPalette) BucketHeader ¶
func (p *StackPalette) BucketHeader(bucket *stack.Bucket, fullPath, multipleBuckets bool) string
BucketHeader prints the header of a goroutine signature.
func (*StackPalette) StackLines ¶
func (p *StackPalette) StackLines(signature *stack.Signature, srcLen, pkgLen int, fullPath bool) string
StackLines prints one complete stack trace, without the header.