func stringToLevel(l string) (zerolog.Level, error) {
	switch strings.ToLower(l) {
	case "debug":
		return zerolog.DebugLevel, nil
	case "info":
		return zerolog.InfoLevel, nil
	case "warn", "warning":
		return zerolog.WarnLevel, nil
	case "error":
		return zerolog.ErrorLevel, nil
	case "fatal":
		return zerolog.FatalLevel, nil
	case "panic":
		return zerolog.PanicLevel, nil
	}
	return zerolog.InfoLevel, errors.Newf("Unknown log level '%s'", l)
}
stringToLevel converts a level string to a zerolog level
package logging
import (
	"os"
	"strings"
	"sync"
	"time"
	"github.com/arangodb/kube-arangodb/pkg/util/errors"
	"github.com/rs/zerolog"
)
type Service interface {
	MustGetLogger(name string) zerolog.Logger
	MustSetLevel(name, level string)
	ConfigureRootLogger(cb func(rootLog zerolog.Logger) zerolog.Logger)
}
type loggingService struct {
	mutex        sync.Mutex
	rootLog      zerolog.Logger
	defaultLevel zerolog.Level
	levels       map[string]zerolog.Level
}
func NewRootLogger() zerolog.Logger {
	return zerolog.New(zerolog.ConsoleWriter{
		Out:        os.Stdout,
		TimeFormat: time.RFC3339Nano,
		NoColor:    true,
	}).With().Timestamp().Logger()
}
func NewService(defaultLevel string, overrides []string) (Service, error) {
	l, err := stringToLevel(defaultLevel)
	if err != nil {
		return nil, errors.WithStack(err)
	}
	rootLog := NewRootLogger()
	s := &loggingService{
		rootLog:      rootLog,
		defaultLevel: l,
		levels:       make(map[string]zerolog.Level),
	}
	for _, override := range overrides {
		levelParts := strings.Split(override, "=")
		switch size := len(levelParts); size {
		case 1:
			level, err := stringToLevel(levelParts[0])
			if err != nil {
				return nil, errors.WithStack(err)
			}
			s.defaultLevel = level
		case 2:
			level, err := stringToLevel(levelParts[1])
			if err != nil {
				return nil, errors.WithStack(err)
			}
			s.levels[levelParts[0]] = level
		default:
			return nil, errors.Newf("invalid log definition %s: Length %d is not equal 1 or 2", override, size)
		}
	}
	return s, nil
}
func (s *loggingService) ConfigureRootLogger(cb func(rootLog zerolog.Logger) zerolog.Logger) {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.rootLog = cb(s.rootLog)
}
func (s *loggingService) MustGetLogger(name string) zerolog.Logger {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	level, found := s.levels[name]
	if !found {
		level = s.defaultLevel
	}
	return s.rootLog.With().Str("component", name).Logger().Level(level)
}
func (s *loggingService) MustSetLevel(name, level string) {
	l, err := stringToLevel(level)
	if err != nil {
		panic(err)
	}
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.levels[name] = l
}