loggo/loglevel.go
2023-11-02 12:37:06 +01:00

45 lines
1.1 KiB
Go

package loggo
import (
"github.com/fatih/color"
)
// struct for log levels
type logLevel struct {
level int
name string
color color.Color
}
// debug log level (level = 0, name = "debug")
var DebugLevel = logLevel{0, "debug", *color.New(color.FgCyan)}
// info log level (level = 1, name = "info")
var InfoLevel = logLevel{1, "info", *color.New(color.FgGreen)}
// warning log level (level = 2, name = "warning")
var WarningLevel = logLevel{2, "warning", *color.New(color.FgYellow)}
// error log level (level = 3, name = "error")
var ErrorLevel = logLevel{3, "error", *color.New(color.FgRed)}
// fatal log level (level = 4, name = "fatal")
var FatalLevel = logLevel{4, "fatal", *color.New(color.FgRed).Add(color.Bold)}
// current log level (defaults to: "infoLevel")
var currentLevel = InfoLevel
// return current set log level
func GetLogLevel() logLevel {
return currentLevel
}
// set current log level
func SetLogLevel(level logLevel) {
currentLevel = level
}
// set the color of a log level
func (level *logLevel) SetColor(color color.Color) {
level.color = color
}