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
1 changed files with 16 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"sync"
) )
// Error returned if a Producer has run to its end. // 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 transparent = true
} }
} else { } 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 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 { func (db *DecodedBlock) AirOnly() bool {
return db.AirId != -1 && len(db.IndexMap) == 0 return db.AirId != -1 && len(db.IndexMap) == 0
} }