From 4759e43ff7f29727477b0d928047bf5ca283cef1 Mon Sep 17 00:00:00 2001 From: Rajamohan Raj Date: Sat, 29 Aug 2020 02:47:00 +0000 Subject: Add log level support for orchestrator In this patch, a new config item for log-level is added, default log-level is set as "warn", for detailed logs, set log-level as "info" Issue-ID: MULTICLOUD-1200 Signed-off-by: Rajamohan Raj Change-Id: I3205ce110a492ecc6a7c680e3d35e173a5624bb0 --- src/orchestrator/pkg/infra/logutils/logger.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/orchestrator/pkg/infra/logutils/logger.go') diff --git a/src/orchestrator/pkg/infra/logutils/logger.go b/src/orchestrator/pkg/infra/logutils/logger.go index 2e8f9969..209114a3 100644 --- a/src/orchestrator/pkg/infra/logutils/logger.go +++ b/src/orchestrator/pkg/infra/logutils/logger.go @@ -2,6 +2,9 @@ package logutils import ( log "github.com/sirupsen/logrus" + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config" + "strings" + ) //Fields is type that will be used by the calling function @@ -10,6 +13,13 @@ type Fields map[string]interface{} func init() { // Log as JSON instead of the default ASCII formatter. log.SetFormatter(&log.JSONFormatter{}) + if strings.EqualFold(config.GetConfiguration().LogLevel, "warn") { + log.SetLevel(log.WarnLevel) + + } + if strings.EqualFold(config.GetConfiguration().LogLevel, "info") { + log.SetLevel(log.InfoLevel) + } } // Error uses the fields provided and logs @@ -26,3 +36,4 @@ func Warn(msg string, fields Fields) { func Info(msg string, fields Fields) { log.WithFields(log.Fields(fields)).Info(msg) } + -- cgit 1.2.3-korg