package common

import (
	"fmt"

	"github.com/rs/zerolog"
)

// SetLogLevel takes in the integer supplied and turns it into a log level
func SetLogLevel(loglevel int) (level zerolog.Level, err error) {
	switch loglevel {
	case -1:
		return zerolog.TraceLevel, nil
	case 0:
		return zerolog.DebugLevel, nil
	case 1:
		return zerolog.InfoLevel, nil
	case 2:
		return zerolog.WarnLevel, nil
	case 3:
		return zerolog.ErrorLevel, nil
	case 4:
		return zerolog.FatalLevel, nil
	case 5:
		return zerolog.PanicLevel, nil
	default:
		return zerolog.InfoLevel, fmt.Errorf("incorrect log level set, setting it to info level")
	}
}
