Documentation ¶
Overview ¶
Package apachelog provides an Apache log parser.
Index ¶
- Constants
- type AccessLogEntry
- type Format
- type Parser
- type RequestFirstLine
- func (rfl *RequestFirstLine) GobDecode(b []byte) error
- func (rfl RequestFirstLine) GobEncode() ([]byte, error)
- func (rfl *RequestFirstLine) Method() string
- func (rfl *RequestFirstLine) Path() string
- func (rfl *RequestFirstLine) Protocol() string
- func (rfl *RequestFirstLine) QueryValues() url.Values
- func (rfl *RequestFirstLine) RawPath() string
- func (rfl RequestFirstLine) String() string
- func (rfl *RequestFirstLine) URL() url.URL
Constants ¶
const ( CombinedLogFromat = "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"" CommonLogFormat = "%h %l %u %t \"%r\" %s %b" )
Most commonly used log formats.
const StandardEnglishFormat = "02/Jan/2006:15:04:05 -0700"
StandardEnglishFormat is the time layout to use for parsing %t format.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessLogEntry ¶
type AccessLogEntry struct { RemoteIPAddr string // Remote IP address LocalIPAddr string // Local IP address ResponseSize int64 // Size of response in bytes, excluding HTTP headers Cookies map[string]string // Cookies value ElapsedTime int64 // Time taken to serve the request, in microseconds EnvVars map[string]string // Content of the environment variables Headers map[string]string // Content of the request headers Filename string // Filename RemoteHost string // Remote host RequestProto string // Request protocol KeepAliveRequests int64 // Number of keepalive requests handled on this connection RemoteLogname string // Remote logname. A "-" is returned, when not supplied RequestMethod string // Request method Port string // Canonical port of the server serving the request ProcessID int64 // Process ID of the child that serviced the request QueryString string // Query string (prepended with a ? if exists) RequestFirstLine RequestFirstLine // First line of the request Status string // Status Time time.Time // Time the request was received (standard english format) ElapsedTimeSec int64 // Time taken to serve the request, in seconds RemoteUser string // Remote user (from auth) URLPath string // URL path requested, not including any query string CanonicalServerName string // Canonical ServerName of the server serving the request ServerName string // Server name according to the UseCanonicalName setting BytesReceived int64 // Bytes received, including request and headers BytesSent int64 // Bytes sent, including headers }
An AccessLogEntry represents a line of an access log.
type Format ¶
type Format int
Format supported by the Apache mod_log_config module. For more information, see:
https://httpd.apache.org/docs/2.4/en/mod/mod_log_config.html#formats
const ( REMOTE_IP_ADDRESS Format // %a LOCAL_IP_ADDRESS // %A RESPONSE_SIZE // %B RESPONSE_SIZE_CLF // %b COOKIE // %{Foobar}C ELAPSED_TIME // %D ENV_VAR // %{FOOBAR}e HEADER // %{Foobar}i FILENAME // %f REMOTE_HOST // %h REQUEST_PROTO // %H REMOTE_LOGNAME // %l REQUEST_METHOD // %m PORT // %p PROCESS_ID // %P QUERY_STRING // %q REQUEST_FIRST_LINE // %r STATUS // %s TIME // %t REMOTE_USER // %u URL_PATH // %U CANONICAL_SERVER_NAME // %v SERVER_NAME // %V BYTES_RECEIVED // %I BYTES_SENT // %O ELAPSED_TIME_IN_SEC // %T UNKNOWN // for errors )
Supported formats.
TODO(gilliek): move complex format, such as COOKIE, at the bottom of the list in order to treat them separately.
func LookupFormat ¶
LookupFormat retrieves the format corresponding to the given format string.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
A Parser for parsing Apaache access log files.
func CombinedParser ¶
CombinedParser creates a new parser that reads from r and that parses log entries using the Apache Combined Log format.
func CommonParser ¶
CommonParser creates a new parser that reads from r and that parses log entries using the Apache Common Log format.
func CustomParser ¶
CustomParser creates a new parser that reads from r and that is capable of parsing log entries having the given format.
The format is mostly the same as the one defined by the mod_log_config Apache module:
https://httpd.apache.org/docs/2.4/en/mod/mod_log_config.html#formats
However, unlike the Apache format, it does not support modifiers of any kind (<, >, !, ...).
func (*Parser) Parse ¶
func (p *Parser) Parse() (*AccessLogEntry, error)
Parse the next access log entry. If there is no more data to read and parse, an io.EOF error is returned.
type RequestFirstLine ¶
type RequestFirstLine struct {
// contains filtered or unexported fields
}
RequestFirstLine is a handy structure to hold the first line of the HTTP request. It provides accessors to access the HTTP method, the path and the protocol information contained in the raw first line.
func NewRequestFirstLine ¶
func NewRequestFirstLine(raw string) RequestFirstLine
NewRequestFirstLine creates a new RequestFirstLine with the supplied raw first line.
This function does not parse or do anything else than initializing the structure.
func (*RequestFirstLine) GobDecode ¶
func (rfl *RequestFirstLine) GobDecode(b []byte) error
func (RequestFirstLine) GobEncode ¶
func (rfl RequestFirstLine) GobEncode() ([]byte, error)
func (*RequestFirstLine) Method ¶
func (rfl *RequestFirstLine) Method() string
Method returns the method held in the HTTP request first line.
func (*RequestFirstLine) Path ¶
func (rfl *RequestFirstLine) Path() string
Path returns the parsed path (without url "percent encoding") held in the HTTP request first line.
func (*RequestFirstLine) Protocol ¶
func (rfl *RequestFirstLine) Protocol() string
Protocol returns the protocol held in the HTTP request first line.
func (*RequestFirstLine) QueryValues ¶
func (rfl *RequestFirstLine) QueryValues() url.Values
QueryValues returns query values (url.Values) derived from URL.RawQuery
func (*RequestFirstLine) RawPath ¶
func (rfl *RequestFirstLine) RawPath() string
RawPath returns the raw path held in the HTTP request first line.
func (RequestFirstLine) String ¶
func (rfl RequestFirstLine) String() string
func (*RequestFirstLine) URL ¶
func (rfl *RequestFirstLine) URL() url.URL
URL returns url.URL structure derived from the raw path