mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
VAULT-9427: Add read support to sys/loggers endpoints (#17979)
* add logger->log-level str func * ensure SetLogLevelByName accounts for duplicates * add read handlers for sys/loggers endpoints * add changelog entry * update docs * ignore base logger * fix docs formatting issue * add ReadOperation support to TestSystemBackend_Loggers * add more robust checks to TestSystemBackend_Loggers * add more robust checks to TestSystemBackend_LoggersByName * check for empty name in delete handler
This commit is contained in:
@@ -112,6 +112,8 @@ func ParseLogFormat(format string) (LogFormat, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// ParseLogLevel returns the hclog.Level that corresponds with the provided level string.
|
||||
// This differs hclog.LevelFromString in that it supports additional level strings.
|
||||
func ParseLogLevel(logLevel string) (log.Level, error) {
|
||||
var result log.Level
|
||||
logLevel = strings.ToLower(strings.TrimSpace(logLevel))
|
||||
@@ -133,3 +135,24 @@ func ParseLogLevel(logLevel string) (log.Level, error) {
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// TranslateLoggerLevel returns the string that corresponds with logging level of the hclog.Logger.
|
||||
func TranslateLoggerLevel(logger log.Logger) (string, error) {
|
||||
var result string
|
||||
|
||||
if logger.IsTrace() {
|
||||
result = "trace"
|
||||
} else if logger.IsDebug() {
|
||||
result = "debug"
|
||||
} else if logger.IsInfo() {
|
||||
result = "info"
|
||||
} else if logger.IsWarn() {
|
||||
result = "warn"
|
||||
} else if logger.IsError() {
|
||||
result = "error"
|
||||
} else {
|
||||
return "", fmt.Errorf("unknown log level")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user