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

55 lines
1.0 KiB
Go
Raw Normal View History

2021-04-26 13:52:50 +02:00
package logger
import (
"fmt"
"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 {
2022-03-16 10:17:32 +02:00
logrus.SetOutput(os.Stdout)
2021-04-26 13:52:50 +02:00
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{})
case "gcp":
logrus.SetFormatter(&logrus.JSONFormatter{
FieldMap: logrus.FieldMap{
"level": "severity",
"msg": "message",
},
})
2021-04-26 13:52:50 +02:00
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
}