Documentation
¶
Overview ¶
Package weblogs provides access logs for webservers written in go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler wraps a handler creating access logs. Access logs are written to stderr using SimpleLogger(). Returned handler must be wrapped by context.ClearHandler.
func HandlerWithOptions ¶
HandlerWithOptions wraps a handler creating access logs and allows caller to configure how access logs are written. Returned handler must be wrapped by context.ClearHandler.
Types ¶
type Capture ¶
type Capture interface {
http.ResponseWriter
// HasStatus returns true if server has sent a status. False means that
// server failed to send a response.
HasStatus() bool
}
Capture captures a server response. Implementations delegate to an underlying ResponseWriter.
type LogRecord ¶
type LogRecord struct {
// The time request was received.
T time.Time
// The request snapshot
R Snapshot
// The capture of the response
W Capture
// Time spent processing the request
Duration time.Duration
// Additional information added with the Writer method.
Extra string
// Key-value pairs to be logged.
Values map[interface{}]interface{}
}
LogRecord represents a single entry in the access logs.
type Logger ¶
type Logger interface {
// NewSnapshot creates a new snapshot of a request.
NewSnapshot(r *http.Request) Snapshot
// NewCapture creates a new capture for capturing a response. w is the
// original ResponseWriter.
NewCapture(w http.ResponseWriter) Capture
// Log writes the log record.
Log(w io.Writer, record *LogRecord)
}
Logger represents an access log format. Clients are free to provide their own implementations.
func ApacheCombinedLogger ¶
func ApacheCombinedLogger() Logger
ApacheCombinedLogger provides access logs in apache combined log format.
func ApacheCommonLogger ¶
func ApacheCommonLogger() Logger
ApacheCommonLogger provides access logs in apache common log format.
func SimpleLogger ¶
func SimpleLogger() Logger
SimpleLogger provides access logs with the following columns: date, remote address, method, URI, status, time elapsed milliseconds, followed by any additional information provided via the Writer method.
type Options ¶
type Options struct {
// Where to write the web logs. nil means write to stderr,
Writer io.Writer
// How to write the web logs. nil means SimpleLogger().
Logger Logger
// How to get current time. nil means use time.Now(). This field is used
// for testing purposes.
Now func() time.Time
}
Options specifies options for writing to access logs.