Documentation
¶
Index ¶
- Constants
- Variables
- type Logger
- func (hl *Logger) Close()
- func (hl *Logger) Log(r *http.Request, m Metrics)
- func (hl *Logger) LogAtTime(r *http.Request, m Metrics, t time.Time)
- func (hl *Logger) OpenFile(name string) (err error)
- func (hl *Logger) Parse(format string)
- func (hl *Logger) ReopenFile() (err error)
- func (hl *Logger) SetWriter(w io.Writer)
- type Metrics
Constants ¶
const ( TextSegment = iota ConvSegment )
Variables ¶
var ( // This error is returned by the ReopenFile function, if no output filename is associated with // the logger. ErrNoFile = fmt.Errorf("not a file") )
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
HTTP Logger object.
func New ¶
Return a new HTTP logger. Format is the log format to use. Trustedlist is a list of IP addresses or CIDRs, that are considered trusted for the purpose of parsing the X-Forwarded-For header.
func (*Logger) Log ¶
Log the request r. The metrics supplies information about request handling. Mark the entry with the current timestamp.
func (*Logger) LogAtTime ¶
Log the request r. The metrics supplies information about request handling. Time marks the end of the request processing.
func (*Logger) Parse ¶
Parse the format string.
Supported conversion specifiers:
%% The percent sign.
%a Client IP address of the request. Determined using X-Forwarded-From, if available.
%{c}a Underlying peer IP address of the connection.
%A Local IP-address. Uses Metrics.Listen().
%B Size of response in bytes, excluding HTTP headers. Uses Metrics.Size().
%b Same as above, but in CLF format, i.e. a '-' rather than a 0 when no bytes are sent.
%D The time taken to serve the request, in microseconds.
%{VAR}e The contents of the environment variable VAR.
%h Remote hostname.
%H The request protocol.
%{FIELD}i The contents of FIELD: header line in the request (only the first value in case of multiple headers).
%l Remote logname, as returned by Metrics.Ident().
%m The request method.
%p The canonical port of the server serving the request, as reported by Metrics.Listen().
%q The query string (prepended with a ? if a query string exists, otherwise an empty string).
%r First line of request.
%R Name of the handler generating the response, as returned by Metrics.Handler().
%s, %>s Response status, as returned by Metrics.Status()
%t Time the request was received, in the format [02/Jan/2016:15:04:05 -0700].
%{FORMAT}t Time the request was received, in the form given by strftime(3) FORMAT.
%T The time taken to serve the request, in seconds. Reported by Metrics.Duration().
%{UNIT}T The time taken to serve the request, in UNITs (ms, us, s).
%u Remote user if the request was authenticated. Supplied by r.URL.User.
%U The URL path requested, not including any query string.
%v, %V The canonical name of the server serving the request (given by r.Host).
func (*Logger) ReopenFile ¶
If hl is a logger associated with a disk file, close the file and open it again. This is intended for use after rotating the log file.
type Metrics ¶
type Metrics interface {
// IP[:PORT] of the HTTP server
// %A, %p
Listen() string
// Handler name. Its semantics is up to the calling implementation.
// %R
Handler() string
// Remote logname (from identd, or the like).
// %l
Ident() string
// HTTP response status code.
// %s, %>s
Status() int
// The time taken to serve the request.
// %D, %T
Duration() time.Duration
// Size of response in bytes.
// %B, %b
Size() int64
}
Supplies additional data for certain conversion specifiers.