diff --git a/cmd/gotail/.gitignore b/cmd/gotail/.gitignore new file mode 100644 index 0000000..6249af5 --- /dev/null +++ b/cmd/gotail/.gitignore @@ -0,0 +1 @@ +gotail diff --git a/cmd/gotail/Makefile b/cmd/gotail/Makefile new file mode 100644 index 0000000..5d0c308 --- /dev/null +++ b/cmd/gotail/Makefile @@ -0,0 +1,4 @@ +default: gotail + +gotail: *.go ../../*.go + GOPATH=~/as/logyard go build diff --git a/cmd/tail/main.go b/cmd/gotail/gotail.go similarity index 60% rename from cmd/tail/main.go rename to cmd/gotail/gotail.go index 3ce45a7..96b9a64 100644 --- a/cmd/tail/main.go +++ b/cmd/gotail/gotail.go @@ -4,10 +4,9 @@ import ( "fmt" "logyard/tail" "flag" + "os" ) -var samplefile = "/tmp/test" - func args2config() tail.Config { config := tail.Config{Follow: true} flag.IntVar(&config.Location, "n", 0, "tail from the last Nth location") @@ -21,7 +20,25 @@ func args2config() tail.Config { } func main() { - t, err := tail.TailFile(samplefile, args2config()) + config := args2config() + if flag.NFlag() < 1 { + fmt.Println("need one or more files as arguments") + os.Exit(1) + } + + done := make(chan bool) + for _, filename := range flag.Args() { + go tailFile(filename, config, done) + } + + for _, _ = range flag.Args() { + <-done + } +} + +func tailFile(filename string, config tail.Config, done chan bool) { + defer func() { done <- true }() + t, err := tail.TailFile(filename, config) if err != nil { fmt.Println(err) return diff --git a/cmd/tail/.gitignore b/cmd/tail/.gitignore deleted file mode 100644 index e84fa9b..0000000 --- a/cmd/tail/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tail diff --git a/cmd/tail/Makefile b/cmd/tail/Makefile deleted file mode 100644 index 2ccd60c..0000000 --- a/cmd/tail/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -default: tail - -tail: *.go - GOPATH=~/as/logyard go build diff --git a/tail.go b/tail.go index 58f241a..66279c1 100644 --- a/tail.go +++ b/tail.go @@ -99,9 +99,8 @@ func (tail *Tail) reopen() error { tail.file, err = os.Open(tail.Filename) if err != nil { if os.IsNotExist(err) { - log.Printf("Waiting for the file to appear...") + log.Printf("Waiting for %s to appear...", tail.Filename) err := tail.watcher.BlockUntilExists() - log.Println(err) if err != nil { return fmt.Errorf("Failed to detect creation of %s: %s", tail.Filename, err) }