diff --git a/bin/vproxy/main.go b/bin/vproxy/main.go index de63b0c..76d0ff7 100644 --- a/bin/vproxy/main.go +++ b/bin/vproxy/main.go @@ -87,7 +87,7 @@ func tailLogs(c *cli.Context) error { hostname := c.Args().First() client := createClient(c) - client.Attach(hostname) + client.Tail(hostname, !c.Bool("no-follow")) return nil } diff --git a/client.go b/client.go index d207652..bf15bf7 100644 --- a/client.go +++ b/client.go @@ -84,12 +84,12 @@ func (c *Client) addBinding(bind string, detach bool) { if detach { c.wg.Done() } else { - c.Attach(s[0]) + c.Tail(s[0], true) } res.Body.Close() } -func (c *Client) Attach(hostname string) { +func (c *Client) Tail(hostname string, follow bool) { data := url.Values{} data.Add("host", hostname) res, err := http.DefaultClient.PostForm(c.uri("/clients/stream"), data) @@ -98,14 +98,17 @@ func (c *Client) Attach(hostname string) { log.Fatalf("error registering client: %s\n", err) } fmt.Printf("[*] streaming logs for %s\n", hostname) - streamLogs(res) + streamLogs(res, follow) } -func streamLogs(res *http.Response) { +func streamLogs(res *http.Response, follow bool) { defer res.Body.Close() r := bufio.NewReader(res.Body) for { line, err := r.ReadString('\n') + if line == "---\n" && !follow { + os.Exit(0) + } if err != nil { if line != "" && strings.Contains(line, "error") { fmt.Println(line) diff --git a/daemon.go b/daemon.go index 3063f4c..c826bfd 100644 --- a/daemon.go +++ b/daemon.go @@ -221,6 +221,7 @@ func (d *Daemon) relayLogsUntilClose(vhost *Vhost, w http.ResponseWriter, reqCtx buff := vhost.BufferAsString() if buff != "" { fmt.Fprint(w, buff) + fmt.Fprintln(w, "---") } // Listen to connection close and un-register logChan