mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
49 lines
883 B
Go
49 lines
883 B
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
logrus "github.com/sirupsen/logrus"
|
|
|
|
"github.com/imgproxy/imgproxy/v3/config/configurators"
|
|
)
|
|
|
|
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
|
|
}
|