From eeb05eb976b8f469c013c3844a0f27454a183604 Mon Sep 17 00:00:00 2001 From: Chris Ainsworth-Patrick Date: Thu, 15 Aug 2024 11:58:03 +0100 Subject: [PATCH] allow setting log format to json --- log.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/log.go b/log.go index 8754b31..2ebc209 100644 --- a/log.go +++ b/log.go @@ -51,11 +51,16 @@ func init() { Log.SetLevel(logrus.WarnLevel) } } - Log.SetFormatter(&logrus.TextFormatter{ - DisableTimestamp: true, - PadLevelText: true, - ForceColors: runtime.GOOS != "windows", - }) + + if v, ok := os.LookupEnv("ATOMIST_LOG_FORMAT"); ok && v == "json" { + Log.SetFormatter(&logrus.JSONFormatter{}) + } else { + Log.SetFormatter(&logrus.TextFormatter{ + DisableTimestamp: true, + PadLevelText: true, + ForceColors: runtime.GOOS != "windows", + }) + } // try to obtain the GCP project id if _, ok := os.LookupEnv("K_SERVICE"); ok {