本文整理匯總了Golang中github.com/hpcloud/tail.SeekInfo類的典型用法代碼示例。如果您正苦於以下問題:Golang SeekInfo類的具體用法?Golang SeekInfo怎麽用?Golang SeekInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SeekInfo類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: logHandler
func logHandler(w http.ResponseWriter, r *http.Request, file string) {
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
apilog.Println(err)
return
}
defer conn.Close()
var more string
var offset tail.SeekInfo
offset.Whence = 2
fi, err := os.Open(file)
if err != nil {
apilog.Println(err)
}
f, err := fi.Stat()
if err != nil {
apilog.Println(err)
}
if f.Size() < 10000 {
offset.Offset = f.Size() * (-1)
} else {
offset.Offset = -10000
more = "... "
}
fi.Close()
conf := tail.Config{
Follow: true,
ReOpen: true,
Location: &offset,
Logger: tail.DiscardingLogger,
}
t, err := tail.TailFile(file, conf)
if err != nil {
apilog.Println(err)
}
for line := range t.Lines {
if line.Err == nil {
if err = conn.WriteMessage(websocket.TextMessage, []byte(more+line.Text)); err != nil {
apilog.Println(err)
return
}
more = ""
} else {
apilog.Println(err)
}
}
}
示例2: Start
func (t *Tail) Start(acc telegraf.Accumulator) error {
t.Lock()
defer t.Unlock()
t.acc = acc
var seek tail.SeekInfo
if !t.FromBeginning {
seek.Whence = 2
seek.Offset = 0
}
var errS string
// Create a "tailer" for each file
for _, filepath := range t.Files {
g, err := globpath.Compile(filepath)
if err != nil {
log.Printf("E! Error Glob %s failed to compile, %s", filepath, err)
}
for file, _ := range g.Match() {
tailer, err := tail.TailFile(file,
tail.Config{
ReOpen: true,
Follow: true,
Location: &seek,
MustExist: true,
})
if err != nil {
errS += err.Error() + " "
continue
}
// create a goroutine for each "tailer"
t.wg.Add(1)
go t.receiver(tailer)
t.tailers = append(t.tailers, tailer)
}
}
if errS != "" {
return fmt.Errorf(errS)
}
return nil
}
示例3: Start
func (l *LogParserPlugin) Start(acc telegraf.Accumulator) error {
l.Lock()
defer l.Unlock()
l.acc = acc
l.lines = make(chan string, 1000)
l.done = make(chan struct{})
// Looks for fields which implement LogParser interface
l.parsers = []LogParser{}
s := reflect.ValueOf(l).Elem()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
if !f.CanInterface() {
continue
}
if lpPlugin, ok := f.Interface().(LogParser); ok {
if reflect.ValueOf(lpPlugin).IsNil() {
continue
}
l.parsers = append(l.parsers, lpPlugin)
}
}
if len(l.parsers) == 0 {
return fmt.Errorf("ERROR: logparser input plugin: no parser defined.")
}
// compile log parser patterns:
for _, parser := range l.parsers {
if err := parser.Compile(); err != nil {
return err
}
}
var seek tail.SeekInfo
if !l.FromBeginning {
seek.Whence = 2
seek.Offset = 0
}
l.wg.Add(1)
go l.parser()
var errS string
// Create a "tailer" for each file
for _, filepath := range l.Files {
g, err := globpath.Compile(filepath)
if err != nil {
log.Printf("ERROR Glob %s failed to compile, %s", filepath, err)
}
for file, _ := range g.Match() {
tailer, err := tail.TailFile(file,
tail.Config{
ReOpen: true,
Follow: true,
Location: &seek,
})
if err != nil {
errS += err.Error() + " "
continue
}
// create a goroutine for each "tailer"
l.wg.Add(1)
go l.receiver(tailer)
l.tailers = append(l.tailers, tailer)
}
}
if errS != "" {
return fmt.Errorf(errS)
}
return nil
}