Browse Source

Add: IMGPROXY_LOG_LEVEL environment config for set Logrus debug level (#240)

William Pain 5 years ago
parent
commit
e4f787e1f7
2 changed files with 10 additions and 1 deletions
  1. 1 0
      docs/configuration.md
  2. 9 1
      log.go

+ 1 - 0
docs/configuration.md

@@ -222,6 +222,7 @@ imgproxy can report occurred errors to Bugsnag, Honeybadger and Sentry:
   * `pretty`: _(default)_ colored human-readable format;
   * `structured`: machine-readable format;
   * `json`: JSON format;
+* `IMGPROXY_LOG_LEVEL`: the log level. The following levels are supported `error`, `warn`, `info` and `debug`. Default: `info`;
 
 imgproxy can send logs to syslog, but this feature is disabled by default. To enable it, set `IMGPROXY_SYSLOG_ENABLE` to `true`:
 

+ 9 - 1
log.go

@@ -19,7 +19,15 @@ func initLog() {
 		logrus.SetFormatter(newLogPrettyFormatter())
 	}
 
-	logrus.SetLevel(logrus.DebugLevel)
+	logLevel := "info"
+	strEnvConfig(&logLevel, "IMGPROXY_LOG_LEVEL")
+
+	levelLogLevel, err := logrus.ParseLevel(logLevel)
+	if err != nil {
+		levelLogLevel = logrus.DebugLevel
+	}
+
+	logrus.SetLevel(levelLogLevel)
 
 	if isSyslogEnabled() {
 		slHook, err := newSyslogHook()