Log missing colors only once to make log output less spammy.

This commit is contained in:
Sascha L. Teichmann 2015-07-20 14:01:01 +02:00
parent 232feaa435
commit 91a50a4622

View File

@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"log"
"sync"
)
// Error returned if a Producer has run to its end.
@ -163,7 +164,7 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
transparent = true
}
} else {
log.Printf("Missing color entry for %s.", name)
logMissing(name)
}
}
}
@ -180,6 +181,20 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error)
return
}
var missingColors = struct {
sync.Mutex
cols map[string]struct{}
}{cols: map[string]struct{}{}}
func logMissing(name string) {
missingColors.Lock()
defer missingColors.Unlock()
if _, found := missingColors.cols[name]; !found {
missingColors.cols[name] = struct{}{}
log.Printf("Missing color entry for %s.\n", name)
}
}
func (db *DecodedBlock) AirOnly() bool {
return db.AirId != -1 && len(db.IndexMap) == 0
}