Created
July 20, 2012 10:25
-
-
Save njpatel/3150044 to your computer and use it in GitHub Desktop.
Go Mindfuck
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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