1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
12 // logScanner is an io.Writer that calls ReportFunc(pattern) the first
13 // time one of the Patterns appears in the data. Patterns must not
15 type logScanner struct {
17 ReportFunc func(string)
22 func (s *logScanner) Write(p []byte) (int, error) {
24 // We only call reportFunc once. Once we've called it
25 // there's no need to buffer/search subsequent writes.
28 split := bytes.LastIndexByte(p, '\n')
32 s.buf.Write(p[:split+1])
34 for _, pattern := range s.Patterns {
35 if strings.Contains(txt, pattern) {
45 n, err := s.buf.Write(p[split+1:])
46 return n + split + 1, err