Override logrus.ErrorKey when json logging is enabled (#2830)

* override logrus.ErrorKey when json logging is enabled

Signed-off-by: Benoit Gagnon <benoit.gagnon@ubisoft.com>

* document the logrus.ErrorKey override

Signed-off-by: Benoit Gagnon <benoit.gagnon@ubisoft.com>

* add changelog entry

Signed-off-by: Benoit Gagnon <benoit.gagnon@ubisoft.com>
pull/2843/head
Benoit Gagnon 2020-08-18 13:53:45 -04:00 committed by GitHub
parent 3a4e441af8
commit 5d2c9e2ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1 @@
When JSON logging format is enabled, place error message at "error.message" instead of "error" for compatibility with Elasticsearch/ELK and the Elastic Common Schema

View File

@ -38,6 +38,23 @@ func DefaultLogger(level logrus.Level, format Format) *logrus.Logger {
if format == FormatJSON {
logger.Formatter = new(logrus.JSONFormatter)
// Error hooks inject nested fields under "error.*" with the error
// string message at "error".
//
// This structure is incompatible with recent Elasticsearch versions
// where dots in field names are automatically expanded to objects;
// field "error" cannot be both a string and an object at the same
// time.
//
// ELK being a popular choice for log ingestion and a common reason
// for enabling JSON logging in the first place, we avoid this mapping
// problem by nesting the error's message at "error.message".
//
// This also follows the Elastic Common Schema (ECS) recommendation.
// https://www.elastic.co/guide/en/ecs/current/ecs-error.html
logrus.ErrorKey = "error.message"
} else {
logrus.ErrorKey = "error"
}
// Make sure the output is set to stdout so log messages don't show up as errors in cloud log dashboards.