Esempio n. 1
0
func tailUlog(ctx *Context) {
	logfile := flagTailFile
	t, err := tail.TailFile(logfile, tail.Config{Poll: true, Follow: true, ReOpen: true, Pipe: true})
	if err != nil {
		log.Error(err)
	}

	// create the workers. line goes in, parsed line goes out
	for i := 0; i < nrCPU/2; i++ {
		go parseLineWorker(ctx)
	}
	// do backup tasks
	go doBackupTask(ctx, "disk")

	//show some stats
	go rateLogger(ctx)

	for line := range t.Lines {
		ctx.lines <- &line.Text
	}
}
Esempio n. 2
0
func (b *diskBackend) RestoreTail(filename string) {
	t, err := tail.TailFile(filename, tail.Config{Poll: true, Follow: true, ReOpen: false, Pipe: false})
	if err != nil {
		log.Error(err)
	}
	i := 0
	for line := range t.Lines {
		l := []byte(line.Text)
		b.ctx.parsedLines <- &l
		i++
		if i == 500000 {
			log.Debug(string(l))
			log.Info("tail read 500000 lines, breaking")
			break
		}
	}
	t.Stop()
	log.Info("removing ", filename)
	os.Remove(b.directory + "/" + b.filename)
	os.Remove(filename)
	time.Sleep(time.Second * 2)
}