Pass log types to logger on creation

graph-rework
noah metz 2023-06-18 18:50:34 -06:00
parent 1d2047eee2
commit 52f77cc186
1 changed files with 3 additions and 3 deletions

@ -20,10 +20,10 @@ type DefaultLogger struct {
init bool init bool
init_lock sync.Mutex init_lock sync.Mutex
loggers map[string]zerolog.Logger loggers map[string]zerolog.Logger
components []string
} }
var log DefaultLogger = DefaultLogger{loggers: map[string]zerolog.Logger{}} var log DefaultLogger = DefaultLogger{loggers: map[string]zerolog.Logger{}, components: []string{"update", "graph", "event", "resource", "manager", "test", "gql", "gqlws", "gqlws_new", "gqlws_hb", "listeners"}}
var all_components = []string{"update", "graph", "event", "resource", "manager", "test", "gql", "vex", "gqlws", "gqlws_new", "gqlws_hb", "listeners"}
func (logger * DefaultLogger) Init(components []string) error { func (logger * DefaultLogger) Init(components []string) error {
logger.init_lock.Lock() logger.init_lock.Lock()
@ -50,7 +50,7 @@ func (logger * DefaultLogger) Init(components []string) error {
} }
writer := io.MultiWriter(file, os.Stdout) writer := io.MultiWriter(file, os.Stdout)
for _, c := range(all_components) { for _, c := range(logger.components) {
if component_enabled(c) == true { if component_enabled(c) == true {
logger.loggers[c] = zerolog.New(writer).With().Timestamp().Str("component", c).Logger() logger.loggers[c] = zerolog.New(writer).With().Timestamp().Str("component", c).Logger()
} }