15370: Re-enable docker tests.
[arvados.git] / lib / crunchrun / logscanner.go
index 9cf60b62bbc849784cd93e8d80c1be310659eae0..aa0a8347ed32ecd2393cb80f1a90e8253ef2e3d9 100644 (file)
@@ -14,7 +14,7 @@ import (
 // contain newlines.
 type logScanner struct {
        Patterns   []string
-       ReportFunc func(string)
+       ReportFunc func(pattern, text string)
        reported   bool
        buf        bytes.Buffer
 }
@@ -32,8 +32,14 @@ func (s *logScanner) Write(p []byte) (int, error) {
        s.buf.Write(p[:split+1])
        txt := s.buf.String()
        for _, pattern := range s.Patterns {
-               if strings.Contains(txt, pattern) {
-                       s.ReportFunc(pattern)
+               if found := strings.Index(txt, pattern); found >= 0 {
+                       // Report the entire line where the pattern
+                       // was found.
+                       txt = txt[strings.LastIndexByte(txt[:found], '\n')+1:]
+                       if end := strings.IndexByte(txt, '\n'); end >= 0 {
+                               txt = txt[:end]
+                       }
+                       s.ReportFunc(pattern, txt)
                        s.reported = true
                        return len(p), nil
                }