added methods to set log level by name and level
This commit is contained in:
parent
8e3cf9378d
commit
20a4d89240
1 changed files with 34 additions and 0 deletions
34
loglevel.go
34
loglevel.go
|
@ -1,6 +1,8 @@
|
|||
package loggo
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
|
@ -39,6 +41,38 @@ func SetLogLevel(level logLevel) {
|
|||
currentLevel = level
|
||||
}
|
||||
|
||||
// set current log level by name
|
||||
func SetLogLevelByName(name string) {
|
||||
switch strings.ToLower(name) {
|
||||
case DebugLevel.name:
|
||||
SetLogLevel(DebugLevel)
|
||||
case InfoLevel.name:
|
||||
SetLogLevel(InfoLevel)
|
||||
case WarningLevel.name:
|
||||
SetLogLevel(WarningLevel)
|
||||
case ErrorLevel.name:
|
||||
SetLogLevel(ErrorLevel)
|
||||
case FatalLevel.name:
|
||||
SetLogLevel(FatalLevel)
|
||||
}
|
||||
}
|
||||
|
||||
// set current log level by level
|
||||
func SetLogLevelByLevel(level int) {
|
||||
switch level {
|
||||
case DebugLevel.level:
|
||||
SetLogLevel(DebugLevel)
|
||||
case InfoLevel.level:
|
||||
SetLogLevel(InfoLevel)
|
||||
case WarningLevel.level:
|
||||
SetLogLevel(WarningLevel)
|
||||
case ErrorLevel.level:
|
||||
SetLogLevel(ErrorLevel)
|
||||
case FatalLevel.level:
|
||||
SetLogLevel(FatalLevel)
|
||||
}
|
||||
}
|
||||
|
||||
// set the color of a log level
|
||||
func (level *logLevel) SetColor(color color.Color) {
|
||||
level.color = color
|
||||
|
|
Loading…
Reference in a new issue