introduce --debug flag to hide excessive error messages by default but allow displaying them

This commit is contained in:
Dominic Breuker
2019-04-24 21:42:18 +02:00
parent 7d9d32412b
commit 8a1838faee
5 changed files with 22 additions and 12 deletions

View File

@@ -16,7 +16,7 @@ type Bindings struct {
type Logger interface {
Infof(format string, v ...interface{})
Errorf(format string, v ...interface{})
Errorf(debug bool, format string, v ...interface{})
Eventf(color int, format string, v ...interface{})
}
@@ -96,7 +96,7 @@ func initFSW(fsw FSWatcher, rdirs, dirs []string, logger Logger) {
case <-doneCh:
return
case err := <-errCh:
logger.Errorf("initializing fs watcher: %v", err)
logger.Errorf(true, "initializing fs watcher: %v", err)
}
}
}
@@ -130,7 +130,7 @@ func triggerEvery(d time.Duration, triggerCh chan struct{}) {
func logErrors(errCh chan error, logger Logger) {
for {
err := <-errCh
logger.Errorf("ERROR: %v", err)
logger.Errorf(true, "ERROR: %v", err)
}
}

View File

@@ -190,6 +190,7 @@ type mockLogger struct {
Info chan string
Error chan string
Event chan string
Debug bool
}
func newMockLogger() *mockLogger {
@@ -197,6 +198,7 @@ func newMockLogger() *mockLogger {
Info: make(chan string, 10),
Error: make(chan string, 10),
Event: make(chan string, 10),
Debug: true,
}
}
@@ -204,8 +206,10 @@ func (l *mockLogger) Infof(format string, v ...interface{}) {
l.Info <- fmt.Sprintf(format, v...)
}
func (l *mockLogger) Errorf(format string, v ...interface{}) {
l.Error <- fmt.Sprintf(format, v...)
func (l *mockLogger) Errorf(debug bool, format string, v ...interface{}) {
if l.Debug == debug {
l.Error <- fmt.Sprintf(format, v...)
}
}
func (l *mockLogger) Eventf(color int, format string, v ...interface{}) {