You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
708 B
49 lines
708 B
package log |
|
|
|
import "strings" |
|
|
|
type Level int8 |
|
|
|
const LevelKey = "level" |
|
const ( |
|
LevelDebug Level = iota - 1 |
|
LevelInfo |
|
LevelWarn |
|
LevelError |
|
LevelFatal |
|
) |
|
|
|
func (l Level) Key() string { |
|
return LevelKey |
|
} |
|
func (l Level) String() string { |
|
switch l { |
|
case LevelDebug: |
|
return "DEBUG" |
|
case LevelInfo: |
|
return "INFO" |
|
case LevelWarn: |
|
return "WARN" |
|
case LevelError: |
|
return "ERROR" |
|
case LevelFatal: |
|
return "FATAL" |
|
default: |
|
return "" |
|
} |
|
} |
|
func ParseLevel(s string) Level { |
|
switch strings.ToUpper(s) { |
|
case "DEBUG": |
|
return LevelDebug |
|
case "INFO": |
|
return LevelInfo |
|
case "WARN": |
|
return LevelWarn |
|
case "ERROR": |
|
return LevelError |
|
case "FATAL": |
|
return LevelFatal |
|
} |
|
return LevelInfo |
|
}
|
|
|