Skip to content

Commit

Permalink
Consider the case where a host field is at the beginning of the LTSV …
Browse files Browse the repository at this point in the history
…log in `GuessParser`.
  • Loading branch information
Songmu committed Jul 28, 2017
1 parent 9a18d5e commit 1cb2d7d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion axslogparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const clfTimeLayout = "02/Jan/2006:15:04:05 -0700"
// GuessParser guesses the parser from line
func GuessParser(line string) (Parser, *Log, error) {
var p Parser
if strings.Contains(line, "\thost:") {
if strings.Contains(line, "\thost:") || strings.Contains(line, "\ttime:") {
p = &LTSV{}
l, err := p.Parse(line)
if err == nil {
Expand Down
27 changes: 27 additions & 0 deletions axslogparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,33 @@ var parseTests = []struct {
Protocol: "HTTP/1.0",
},
},
{
Name: "LTSV(host field at the beginning)",
Input: "host:192.0.2.1\t" +
"time:08/Mar/2017:14:12:40 +0900\t" +
"req:POST /api/v0/tsdb HTTP/1.1\t" +
"status:200\t" +
"size:36\t" +
"ua:mackerel-agent/0.31.2 (Revision 775fad2)\t" +
"reqtime:0.087\t" +
"taken_sec:0.087\t" +
"vhost:mackerel.io",
Output: Log{
VirtualHost: "mackerel.io",
Host: "192.0.2.1",
Time: time.Date(2017, time.March, 8, 14, 12, 40, 0, loc),
TimeStr: "08/Mar/2017:14:12:40 +0900",
Request: "POST /api/v0/tsdb HTTP/1.1",
Status: 200,
Size: 36,
UserAgent: "mackerel-agent/0.31.2 (Revision 775fad2)",
ReqTime: pfloat64(0.087),
TakenSec: pfloat64(0.087),
Method: "POST",
RequestURI: "/api/v0/tsdb",
Protocol: "HTTP/1.1",
},
},
}

func TestParse(t *testing.T) {
Expand Down

0 comments on commit 1cb2d7d

Please sign in to comment.