From cfa4b596d1f31656f9116cc16f2a4ff7d15c2837 Mon Sep 17 00:00:00 2001 From: Christopher Brookes Date: Sat, 5 Nov 2022 13:20:57 +0100 Subject: [PATCH] feat(logger): implement structured log formatter gcp compliant (#1028) * feat(logger): implement structured log formatter gcp compliant * docs: add new gcp logging format --- docs/configuration.md | 1 + logger/log.go | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 69ef1c94..36202b69 100644 --- a/docs/configuration.md +++ b/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`: diff --git a/logger/log.go b/logger/log.go index f7d7c632..02ba9926 100644 --- a/logger/log.go +++ b/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()) }