Documentation ¶
Overview ¶
Package logparse parses a log entry in the most common formats.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct { // The IP of the client which made the request (nil if unknown). Host net.IP // The username of the logged in user making the request (empty if anonymous). User string // The time the request was made (zero value if unknown, check with IsZero). Time time.Time // The HTTP request line from the client (nil if unknown). Request *http.Request // The HTTP status code returned to the client (-1 if unknown). Status int // The size in bytes of the data sent to the client (0 if no data sent). Bytes int // The URL of the host the client comes from (nil if unknown). Referer *url.URL // The user agent of the client (nil if unknown). UserAgent *useragent.UserAgent }
An Entry represents a log entry.
func Combined ¶
Combined parses a log line containing a log entry in the combined log format.
An entry in the combined log format has the form:
Host - User Time Request Status Bytes Referer UserAgent
basicaly it's the same as the common log format with the added fields:
Referer the URL of the host the client comes from UserAgent the user agent of the client
Example ¶
l, err := Combined(`:: - xojoc [10/Feb/2015:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://xojoc.pw" "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0"`) if err != nil { log.Fatal(err) } fmt.Println(l) fmt.Println(l.Host) fmt.Println(l.User) fmt.Println(l.Time.Format("02/Jan/2006")) fmt.Println(l.Request.URL) fmt.Println(l.Status) fmt.Println(l.Bytes) fmt.Println(l.Referer) fmt.Println(l.UserAgent.Name) fmt.Println(l.UserAgent.OS)
Output: :: - xojoc [10/Feb/2015:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://xojoc.pw" "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0" :: xojoc 10/Feb/2015 /apache_pb.gif 200 2326 http://xojoc.pw Firefox GNU/Linux
func Common ¶
Common parses a log line containing a log entry in the common log format.
An entry in the common log format has the form:
Host - User Time Request Status Bytes
where:
Host is the ip of the client which made the request. - this field never is used. User is the name of the logged in user doing the request. Time is the date/time/zone the request was made. Request is the HTTP request line from the client. Status is the status code returned to the client. Bytes is the size in bytes of the data sent to the client.
Example ¶
l, err := Common(`:: - xojoc [10/Feb/2015:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326`) if err != nil { log.Fatal(err) } fmt.Println(l) fmt.Println(l.Host) fmt.Println(l.User) fmt.Println(l.Time.Format("02/Jan/2006")) fmt.Println(l.Request.URL) fmt.Println(l.Status) fmt.Println(l.Bytes)
Output: :: - xojoc [10/Feb/2015:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 - - :: xojoc 10/Feb/2015 /apache_pb.gif 200 2326
type ExtendedDirective ¶
type ExtendedDirective struct { }
func (*ExtendedDirective) Extended ¶
func (x *ExtendedDirective) Extended(line string) *Entry
Click to show internal directories.
Click to hide internal directories.