log-agent/taillog/taillog.go

28 lines
663 B
Go

package taillog
import (
"fmt"
"github.com/hpcloud/tail"
)
var (
tailChan *tail.Tail
)
//专门从日志文件收集日志的模块
func Init(fileName string) (err error) {
config := tail.Config{
Location: &tail.SeekInfo{Offset: 0, Whence: 2}, //从文件的哪个地方开始读 filebeat记录了文件断点的位置
ReOpen: true, //重新打开,切分用
MustExist: false, //文件不存在不报错
Poll: true,
Follow: true, //是否跟随
}
tailChan, err = tail.TailFile(fileName, config)
if err != nil {
fmt.Printf("tail file error:%s\n", err)
}
return
}