32 lines
725 B
Go
32 lines
725 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
|
|
}
|
|
|
|
func ReadChan() <-chan *tail.Line {
|
|
return tailChan.Lines
|
|
}
|