open-consul/logging/log_levels.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

37 lines
703 B
Go

package logging
import (
"strings"
"github.com/hashicorp/go-hclog"
)
var (
allowedLogLevels = []string{"TRACE", "DEBUG", "INFO", "WARN", "ERR", "ERROR"}
)
func AllowedLogLevels() []string {
var c []string
copy(c, allowedLogLevels)
return c
}
// ValidateLogLevel verifies that a new log level is valid
func ValidateLogLevel(minLevel string) bool {
newLevel := strings.ToUpper(minLevel)
for _, level := range allowedLogLevels {
if level == newLevel {
return true
}
}
return false
}
// Backwards compatibility with former ERR log level
func LevelFromString(level string) hclog.Level {
if strings.ToUpper(level) == "ERR" {
level = "ERROR"
}
return hclog.LevelFromString(level)
}