logtail
作者:互联网
使用第三方模块
"github.com/hpcloud/tail"
初始化Tail指针
package logtail
import (
"fmt"
"github.com/hpcloud/tail"
)
var (
tailObj *tail.Tail
)
func Init(path string) (err error) {
tailObj, err = tail.TailFile(path, tail.Config{Follow: true, ReOpen: true, MustExist: false})
if err != nil {
fmt.Printf("init logtail failed,%v\n", err)
return
}
return
}
读取指针返回的内容
func ReadLinesChan() chan *tail.Line {
return tailObj.Lines
// Lines返回的是一个管道chan,管道里面存的是tail.Line每行的指针
}
从管道里取数据,取的就是文件每行追加的内容
line := <- ReadLinesChan()
fmt.Printf("tail line:%v\n", line.Text)
标签:tailObj,return,err,tail,logtail,指针 来源: https://www.cnblogs.com/PythonOrg/p/16311207.html