Documentation
¶
Index ¶
- Variables
- func DisableConsoleColor()
- func ForceConsoleColor()
- func Logger() app.HandlerFunc
- func LoggerWithConfig(conf LoggerConfig) app.HandlerFunc
- func LoggerWithFormatter(f LogFormatter) app.HandlerFunc
- func LoggerWithWriter(out io.Writer, notLogged ...string) app.HandlerFunc
- type LogFormatter
- type LogFormatterParams
- func (p *LogFormatterParams) AppendErrorMessage(dst []byte) []byte
- func (p *LogFormatterParams) AppendRequestURI(dst []byte) []byte
- func (p *LogFormatterParams) BodySize() int
- func (p *LogFormatterParams) ClientIP() string
- func (p *LogFormatterParams) ErrorMessage() string
- func (p *LogFormatterParams) IsOutputColor() bool
- func (p *LogFormatterParams) MethodColor() string
- func (p *LogFormatterParams) ResetColor() string
- func (p *LogFormatterParams) StatusCodeColor() string
- type LoggerConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultWriter io.Writer = os.Stdout
Functions ¶
func DisableConsoleColor ¶
func DisableConsoleColor()
DisableConsoleColor disables color output in the console.
func ForceConsoleColor ¶
func ForceConsoleColor()
ForceConsoleColor force color output in the console.
func Logger ¶
func Logger() app.HandlerFunc
Logger instances a low-allocation logger middleware that writes directly to DefaultWriter.
func LoggerWithConfig ¶
func LoggerWithConfig(conf LoggerConfig) app.HandlerFunc
LoggerWithConfig instances a low-allocation logger middleware with config.
func LoggerWithFormatter ¶
func LoggerWithFormatter(f LogFormatter) app.HandlerFunc
LoggerWithFormatter instances a low-allocation logger middleware with the specified log formatter.
func LoggerWithWriter ¶
func LoggerWithWriter(out io.Writer, notLogged ...string) app.HandlerFunc
LoggerWithWriter instances a low-allocation logger middleware with the specified writer buffer.
Types ¶
type LogFormatter ¶
type LogFormatter func(w io.Writer, params *LogFormatterParams)
LogFormatter writes log output directly to w.
Implementations must not retain params or any byte slices, map entries, or request pointers referenced by params after the function returns.
type LogFormatterParams ¶
type LogFormatterParams struct {
Request *protocol.Request
// TimeStamp shows the time after the server returns a response.
TimeStamp time.Time
// StatusCode is HTTP response code.
StatusCode int
// Latency is how much time the server cost to process a certain request.
Latency time.Duration
// Method is the HTTP method given to the request.
Method []byte
// Path is the raw path requested by the client.
Path []byte
// Query is the raw query string without the leading '?'.
Query []byte
// Host is the Host header requested by the client.
Host []byte
// Keys are the keys set on the request's context. Treat as read-only.
Keys map[string]any
// contains filtered or unexported fields
}
LogFormatterParams contains zero-copy views into the current request.
Request, Method, Path, Query, Host, and Keys are owned by the active RequestContext and are only valid during the formatter call.
func (*LogFormatterParams) AppendErrorMessage ¶
func (p *LogFormatterParams) AppendErrorMessage(dst []byte) []byte
AppendErrorMessage appends the current private error message without extra string allocations.
func (*LogFormatterParams) AppendRequestURI ¶
func (p *LogFormatterParams) AppendRequestURI(dst []byte) []byte
AppendRequestURI appends the current request URI to dst without extra allocations.
func (*LogFormatterParams) BodySize ¶
func (p *LogFormatterParams) BodySize() int
BodySize returns the response Content-Length when known. It is resolved lazily.
func (*LogFormatterParams) ClientIP ¶
func (p *LogFormatterParams) ClientIP() string
ClientIP returns the client IP. It is resolved lazily.
func (*LogFormatterParams) ErrorMessage ¶
func (p *LogFormatterParams) ErrorMessage() string
ErrorMessage returns private errors for the request. It is resolved lazily.
func (*LogFormatterParams) IsOutputColor ¶
func (p *LogFormatterParams) IsOutputColor() bool
IsOutputColor indicates whether can colors be outputted to the log.
func (*LogFormatterParams) MethodColor ¶
func (p *LogFormatterParams) MethodColor() string
MethodColor is the ANSI color for appropriately logging http method to a terminal.
func (*LogFormatterParams) ResetColor ¶
func (p *LogFormatterParams) ResetColor() string
ResetColor resets all escape attributes.
func (*LogFormatterParams) StatusCodeColor ¶
func (p *LogFormatterParams) StatusCodeColor() string
StatusCodeColor is the ANSI color for appropriately logging http status code to a terminal.
type LoggerConfig ¶
type LoggerConfig struct {
// Optional. Default value is defaultLogFormatter.
Formatter LogFormatter
// Output is a writer where logs are written.
// Optional. Default value is os.Stdout.
Output io.Writer
// SkipPaths is an url path array which logs are not written.
// Optional.
SkipPaths []string
}
LoggerConfig defines the config for Logger middleware.