Skip to content

Instantly share code, notes, and snippets.

@njpatel
Created July 20, 2012 10:25
Show Gist options
  • Save njpatel/3150044 to your computer and use it in GitHub Desktop.
Save njpatel/3150044 to your computer and use it in GitHub Desktop.
Go Mindfuck
func readLogData(filename string, log_id int, logOutputChan chan<- *LogTuple, deathChan chan<- *string) {
cmd := exec.Command("tail", "-f", filename)
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
err = nil
reader := bufio.NewReader(stdout)
sbuffer := ""
lines := 0
for ; err == nil; {
s,err := reader.ReadString('\n')
sbuffer += s
lines += 1
if(lines > 5 ) { //|| time > 1 min) {
logOutputChan <- &LogTuple{ log_id, sbuffer}
sbuffer = ""
lines = 0
}
if err != nil {
deathChan <- &filename
return
}
}
//SetFinalizer
}
go readLogData(alog.Log.Path, alog.Log.Id, logOutputChan, gorDeathChan)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment