2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-01-28 23:50:41 +00:00
|
|
|
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)
|
|
|
|
}
|