1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00
imgproxy/logger/log.go

49 lines
883 B
Go
Raw Normal View History

2021-04-26 13:52:50 +02:00
package logger
import (
"fmt"
"log"
"os"
logrus "github.com/sirupsen/logrus"
2021-09-30 16:23:30 +02:00
"github.com/imgproxy/imgproxy/v3/config/configurators"
2021-04-26 13:52:50 +02:00
)
func Init() error {
log.SetOutput(os.Stdout)
logFormat := "pretty"
logLevel := "info"
configurators.String(&logFormat, "IMGPROXY_LOG_FORMAT")
configurators.String(&logLevel, "IMGPROXY_LOG_LEVEL")
switch logFormat {
case "structured":
logrus.SetFormatter(&structuredFormatter{})
case "json":
logrus.SetFormatter(&logrus.JSONFormatter{})
default:
logrus.SetFormatter(newPrettyFormatter())
}
levelLogLevel, err := logrus.ParseLevel(logLevel)
if err != nil {
levelLogLevel = logrus.InfoLevel
}
logrus.SetLevel(levelLogLevel)
if isSyslogEnabled() {
slHook, err := newSyslogHook()
if err != nil {
return fmt.Errorf("Unable to connect to syslog daemon: %s", err)
}
logrus.AddHook(slHook)
}
return nil
}