Bläddra i källkod

feat(logger): implement structured log formatter gcp compliant (#1028)

* feat(logger): implement structured log formatter gcp compliant

* docs: add new gcp logging format
Christopher Brookes 2 år sedan
förälder
incheckning
cfa4b596d1
2 ändrade filer med 8 tillägg och 0 borttagningar
  1. 1 0
      docs/configuration.md
  2. 7 0
      logger/log.go

+ 1 - 0
docs/configuration.md

@@ -434,6 +434,7 @@ imgproxy can report occurred errors to Bugsnag, Honeybadger and Sentry:
   * `pretty`: _(default)_ colored human-readable format
   * `structured`: machine-readable format
   * `json`: JSON format
+  * `gcp`: Google Cloud Logging agent compliant
 * `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`:

+ 7 - 0
logger/log.go

@@ -23,6 +23,13 @@ func Init() error {
 		logrus.SetFormatter(&structuredFormatter{})
 	case "json":
 		logrus.SetFormatter(&logrus.JSONFormatter{})
+	case "gcp":
+		logrus.SetFormatter(&logrus.JSONFormatter{
+			FieldMap: logrus.FieldMap{
+				"level": "severity",
+				"msg":   "message",
+			},
+		})
 	default:
 		logrus.SetFormatter(newPrettyFormatter())
 	}