basics
This commit is contained in:
44
lvl/lvl.go
Normal file
44
lvl/lvl.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package lvl
|
||||
|
||||
type Level int
|
||||
|
||||
const (
|
||||
Debug Level = iota
|
||||
Info
|
||||
Warn
|
||||
Error
|
||||
)
|
||||
|
||||
// String makes the Level to a string
|
||||
func (l Level) String() string {
|
||||
switch l {
|
||||
case Debug:
|
||||
return "Debug"
|
||||
case Info:
|
||||
return "Info"
|
||||
case Warn:
|
||||
return "Warn"
|
||||
case Error:
|
||||
return "Error"
|
||||
}
|
||||
return "Undefined"
|
||||
|
||||
}
|
||||
|
||||
// Colorize colors a string for the shell matching to its level
|
||||
func (l Level) Colorize(str string) string {
|
||||
var color string
|
||||
|
||||
switch l {
|
||||
case Debug:
|
||||
color = "\033[32m" // green
|
||||
case Info:
|
||||
color = "\033[97m" // white
|
||||
case Warn:
|
||||
color = "\033[33m" // yellow
|
||||
case Error:
|
||||
color = "\033[31m" // red
|
||||
}
|
||||
return color + str + "\033[0m"
|
||||
|
||||
}
|
Reference in New Issue
Block a user