open-consul/agent/consul/logging.go
Chris Piraino 3dd0b59793
Allow users to configure either unstructured or JSON logging (#7130)
* hclog Allow users to choose between unstructured and JSON logging
2020-01-28 17:50:41 -06:00

32 lines
493 B
Go

package consul
import (
"sync"
"github.com/hashicorp/go-hclog"
)
type loggerStore struct {
root hclog.Logger
l sync.Mutex
cache map[string]hclog.Logger
}
func newLoggerStore(root hclog.Logger) *loggerStore {
return &loggerStore{
root: root,
cache: make(map[string]hclog.Logger),
}
}
func (ls *loggerStore) Named(name string) hclog.Logger {
ls.l.Lock()
defer ls.l.Unlock()
l, ok := ls.cache[name]
if !ok {
l = ls.root.Named(name)
ls.cache[name] = l
}
return l
}