Skip to content

Commit

Permalink
printing to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
smn committed Jul 19, 2015
1 parent 0dc18f4 commit 120b838
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions logdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package main
import (
"flag"
"fmt"
"os"

"github.com/ActiveState/tail"
)

func main() {

var filename string
config := tail.Config{Follow: true}

flag.StringVar(&filename, "filename", "", "The file to tail.")
flag.StringVar(&filename, "F", "", " (shorthand for -filename)")
flag.Parse()
Expand All @@ -22,22 +21,25 @@ func main() {
}

done := make(chan bool)
go tailFile(filename, config, done)
go tailFile(filename, tail.Config{Follow: true}, done)
<-done
}

func tailFile(filename string, config tail.Config, done chan bool) {
// when function completes, notify via the channel
defer func() { done <- true }()

// start tailing
t, err := tail.TailFile(filename, config)
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, err)
return
}
for line := range t.Lines {
fmt.Println(line.Text)
}
err = t.Wait()
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, err)
}
}

0 comments on commit 120b838

Please sign in to comment.