|
@@ -16,10 +16,10 @@ type Apache struct {
|
|
}
|
|
}
|
|
|
|
|
|
var logRe = regexp.MustCompile(
|
|
var logRe = regexp.MustCompile(
|
|
- `^(?:(\S+)\s)?` + // %v(The canonical ServerName/virtual host)
|
|
|
|
|
|
+ `^(?:(\S+(?:,\s\S+)*)\s)?` + // %v(The canonical ServerName/virtual host) - 192.168.0.1 or 192.168.0.1,192.168.0.2, 192.168.0.3
|
|
`(\S+)\s` + // %h(Remote Hostname) $remote_addr
|
|
`(\S+)\s` + // %h(Remote Hostname) $remote_addr
|
|
`(\S+)\s` + // %l(Remote Logname)
|
|
`(\S+)\s` + // %l(Remote Logname)
|
|
- `(\S+)\s` + // $remote_user
|
|
|
|
|
|
+ `([\S\s]+)\s` + // $remote_user
|
|
`\[(\d{2}/\w{3}/\d{2}(?:\d{2}:){3}\d{2} [-+]\d{4})\]\s` + // $time_local
|
|
`\[(\d{2}/\w{3}/\d{2}(?:\d{2}:){3}\d{2} [-+]\d{4})\]\s` + // $time_local
|
|
`(.*)`)
|
|
`(.*)`)
|
|
|
|
|
|
@@ -30,11 +30,18 @@ func (ap *Apache) Parse(line string) (*Log, error) {
|
|
return nil, fmt.Errorf("failed to parse apachelog (not matched): %s", line)
|
|
return nil, fmt.Errorf("failed to parse apachelog (not matched): %s", line)
|
|
}
|
|
}
|
|
l := &Log{
|
|
l := &Log{
|
|
- VirtualHost: matches[1],
|
|
|
|
- Host: matches[2],
|
|
|
|
- RemoteUser: matches[3],
|
|
|
|
- User: matches[4],
|
|
|
|
|
|
+ VirtualHost: matches[1],
|
|
|
|
+ Host: matches[2],
|
|
|
|
+ RemoteLogname: matches[3],
|
|
|
|
+ User: matches[4],
|
|
}
|
|
}
|
|
|
|
+ if l.Host == "-" && l.VirtualHost != "" {
|
|
|
|
+ l.Host = l.VirtualHost
|
|
|
|
+ l.VirtualHost = ""
|
|
|
|
+ l.User = fmt.Sprintf("%s %s", l.RemoteLogname, l.User)
|
|
|
|
+ l.RemoteLogname = "-"
|
|
|
|
+ }
|
|
|
|
+
|
|
l.Time, _ = time.Parse(clfTimeLayout, matches[5])
|
|
l.Time, _ = time.Parse(clfTimeLayout, matches[5])
|
|
var rest string
|
|
var rest string
|
|
|
|
|