mfer/internal/log/log.go

46 lines
793 B
Go

package log
import (
"github.com/apex/log"
acli "github.com/apex/log/handlers/cli"
"github.com/pterm/pterm"
)
func DisableStyling() {
pterm.DisableColor()
pterm.DisableStyling()
pterm.Debug.Prefix.Text = ""
pterm.Info.Prefix.Text = ""
pterm.Success.Prefix.Text = ""
pterm.Warning.Prefix.Text = ""
pterm.Error.Prefix.Text = ""
pterm.Fatal.Prefix.Text = ""
}
func Init() {
log.SetHandler(acli.Default)
log.SetLevel(log.InfoLevel)
}
func SetLevel(arg log.Level) {
log.SetLevel(arg)
}
func GetLevel() log.Level {
if logger, ok := log.Log.(*log.Logger); ok {
return logger.Level
}
return 0
}
func IncreaseLevel() {
SetLevel(GetLevel() + 1)
}
func WithError(e error) *log.Entry {
if logger, ok := log.Log.(*log.Logger); ok {
return logger.WithError(e)
}
return nil
}