spiegel/internal/log/init.go
Ada e3bf2ff147
Some checks failed
ci/woodpecker/push/test Pipeline failed
🎉 First commit
2024-04-04 01:16:06 +02:00

33 lines
661 B
Go

package log
import (
"os"
"github.com/sirupsen/logrus"
)
func (config Config) Init() {
if config.File != "" {
file, err := os.OpenFile(config.File, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o640) //nolint:gomnd
if err != nil {
logrus.Fatal("Cannot open log file: ", err)
}
logrus.SetOutput(file)
}
if config.Level == "DEBUG" {
logrus.SetLevel(logrus.DebugLevel)
}
if config.Level == "INFO" {
logrus.SetLevel(logrus.InfoLevel)
}
if config.Level == "WARN" {
logrus.SetLevel(logrus.WarnLevel)
}
if config.Level == "ERROR" {
logrus.SetLevel(logrus.ErrorLevel)
}
if config.Level == "FATAL" {
logrus.SetLevel(logrus.ErrorLevel)
}
}