本文整理汇总了Golang中github.com/hpcloud/tail.Config.ReOpen方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.ReOpen方法的具体用法?Golang Config.ReOpen怎么用?Golang Config.ReOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hpcloud/tail.Config
的用法示例。
在下文中一共展示了Config.ReOpen方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseFile
func (c config) parseFile(ac map[int]Event, f string) map[int]Event {
tc := tail.Config{}
if *c.TailFile {
tc.Follow = true
tc.ReOpen = true
}
//open file for parsing
t, err := tail.TailFile(f, tc)
check(err)
//loop through file contents
for line := range t.Lines {
var lineMap map[string]string
var ok bool
if lineMap, ok = matchLine(lineRe, line.Text); !ok {
continue
}
connum, err := strconv.Atoi(lineMap["conn_num"])
if err != nil {
fmt.Printf("failed to parse '%s' into int\n", lineMap["conn_num"])
}
if connectionMap, ok := matchLine(connectionOpenRe, lineMap["event"]); ok {
//new connection made
ssl := false
if connectionMap["ssl"] == "SSL" {
ssl = true
}
ac[connum] = Event{
Client: connectionMap["client_ip"],
Server: connectionMap["server_ip"],
Connection: connum,
Operation: -2, //number that shouldn't exist in logs
ConnTime: lineMap["time"],
SSL: ssl,
}
continue
}
if _, exists := ac[connum]; !exists {
//skip operation if no connection exists
// this is caused by connections that were created before we started
// parsing the log file.
continue
}
conn := ac[connum]
if sslMap, ok := matchLine(sslCipherRe, lineMap["event"]); ok {
conn.SSLCipher = sslMap["cipher"]
conn.SSLStrength = sslMap["strength"]
ac[connum] = conn
}
if operationMap, ok := matchLine(operationRe, lineMap["event"]); ok {
//new operation
opnum, err := strconv.Atoi(operationMap["opnum"])
if err != nil {
fmt.Printf("failed to parse '%s' into int\n", operationMap["opnum"])
}
if opnum != conn.Operation {
if conn.Operation != -2 {
c.printEvent(conn)
}
if operationMap["operation"] == "BIND" {
if bindDN, ok := matchLine(bindDNRe, lineMap["event"]); ok {
conn.AuthenticatedDN = bindDN["dn"]
} else {
conn.AuthenticatedDN = "__anonymous__"
}
}
conn.OppTime = lineMap["time"]
conn.Operation = opnum
conn.Action = operationMap["operation"]
conn.Requests = make([]string, 0)
conn.Responses = make([]string, 0)
conn.Requests = append(conn.Requests, operationMap["operation"]+operationMap["details"])
} else {
if operationMap["operation"] == "SORT" || operationMap["operation"] == "VLV" {
conn.Requests = append(conn.Requests, operationMap["operation"]+operationMap["details"])
} else {
conn.Responses = append(conn.Responses, operationMap["operation"]+operationMap["details"])
c.printEvent(conn)
conn.Operation = -2
}
}
ac[connum] = conn
}
if connectionClosedRe.MatchString(lineMap["event"]) {
delete(ac, connum)
}
//.........这里部分代码省略.........