Merge pull request #892 from tonistiigi/warnings-summary
Show summary of build warnings.pull/915/head
commit
e482ba2c73
@ -0,0 +1,36 @@
|
||||
package logutil
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func NewFilter(filters ...string) logrus.Hook {
|
||||
dl := logrus.New()
|
||||
dl.SetOutput(ioutil.Discard)
|
||||
return &logsFilter{
|
||||
filters: filters,
|
||||
discardLogger: dl,
|
||||
}
|
||||
}
|
||||
|
||||
type logsFilter struct {
|
||||
filters []string
|
||||
discardLogger *logrus.Logger
|
||||
}
|
||||
|
||||
func (d *logsFilter) Levels() []logrus.Level {
|
||||
return []logrus.Level{logrus.DebugLevel}
|
||||
}
|
||||
|
||||
func (d *logsFilter) Fire(entry *logrus.Entry) error {
|
||||
for _, f := range d.filters {
|
||||
if strings.Contains(entry.Message, f) {
|
||||
entry.Logger = d.discardLogger
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package logutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Pause(l *logrus.Logger) func() {
|
||||
// initialize formatter with original terminal settings
|
||||
l.Formatter.Format(logrus.NewEntry(l))
|
||||
|
||||
bw := newBufferedWriter(l.Out)
|
||||
l.SetOutput(bw)
|
||||
return func() {
|
||||
bw.resume()
|
||||
}
|
||||
}
|
||||
|
||||
type bufferedWriter struct {
|
||||
mu sync.Mutex
|
||||
buf *bytes.Buffer
|
||||
w io.Writer
|
||||
}
|
||||
|
||||
func newBufferedWriter(w io.Writer) *bufferedWriter {
|
||||
return &bufferedWriter{
|
||||
buf: bytes.NewBuffer(nil),
|
||||
w: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (bw *bufferedWriter) Write(p []byte) (int, error) {
|
||||
bw.mu.Lock()
|
||||
defer bw.mu.Unlock()
|
||||
if bw.buf == nil {
|
||||
return bw.w.Write(p)
|
||||
}
|
||||
return bw.buf.Write(p)
|
||||
}
|
||||
|
||||
func (bw *bufferedWriter) resume() {
|
||||
bw.mu.Lock()
|
||||
defer bw.mu.Unlock()
|
||||
if bw.buf == nil {
|
||||
return
|
||||
}
|
||||
io.Copy(bw.w, bw.buf)
|
||||
bw.buf = nil
|
||||
}
|
Loading…
Reference in New Issue