Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandru Cojocaru committed Jun 25, 2015
1 parent 58768da commit c52c769
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ First install the library with:
```
go get github.com/xojoc/logparse
```
*logparse* is simple to use. First parse a string with either [logparse.Common](http://godoc.org/github.com/xojoc/logparse#Common) or [logparse.Combined](http://godoc.org/github.com/xojoc/logparse#Combined) and then access the field of [logparse.Entry](http://godoc.org/github.com/xojoc/logparse#Entry) for the required information. Examples:
* [Common log format](http://godoc.org/github.com/xojoc/logparse#example-Common)
* [Combined log format](http://godoc.org/github.com/xojoc/logparse#example-Combined)
*logparse* is simple to use. First parse a string with either [logparse.Common](http://godoc.org/xojoc.pw/logparse#Common) or [logparse.Combined](http://godoc.org/xojoc.pw/logparse#Combined) and then access the field of [logparse.Entry](http://godoc.org/xojoc.pw/logparse#Entry) for the required information. Examples:
* [Common log format](http://godoc.org/xojoc.pw/logparse#example-Common)
* [Combined log format](http://godoc.org/xojoc.pw/logparse#example-Combined)

see [godoc](http://godoc.org/github.com/xojoc/logparse) for the complete documentation.
see [godoc](http://godoc.org/xojoc.pw/logparse) for the complete documentation.

# Log formats
Right now *logparse* can parse the common and combined log formats. Support is under way for the extended log format.
Expand Down
14 changes: 8 additions & 6 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

package logparse
// Package logparse parses a log entry in the most common formats.
package logparse // import "xojoc.pw/logparse"

import (
"bufio"
"fmt"
"github.com/xojoc/useragent"
"net"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"xojoc.pw/useragent"
)

const timeLayout = "02/Jan/2006:15:04:05 -0700"
Expand All @@ -47,7 +48,6 @@ type Entry struct {
Referer *url.URL
// The user agent of the client (nil if unknown).
UserAgent *useragent.UserAgent
// Cookies map[string]string
}

// Formats the Entry e in the combined log format.
Expand Down Expand Up @@ -241,9 +241,11 @@ func Combined(line string) (*Entry, error) {
if err != nil {
return nil, err
}
e.Referer, err = url.ParseRequestURI(ref)
if err != nil {
return nil, err
if ref != `-` {
e.Referer, err = url.ParseRequestURI(ref)
if err != nil {
return nil, err
}
}

err = expect(l, '"')
Expand Down

0 comments on commit c52c769

Please sign in to comment.