From 91a50a462227e1b7ab221ee04131cd7e6c71a248 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Mon, 20 Jul 2015 14:01:01 +0200 Subject: [PATCH] Log missing colors only once to make log output less spammy. --- common/block.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/common/block.go b/common/block.go index 0f8b864..db3d44d 100644 --- a/common/block.go +++ b/common/block.go @@ -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 }