spiegel/internal/log/init.go

34 lines
661 B
Go
Raw Normal View History

2024-04-04 01:12:42 +02:00
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)
}
}