From 5b21b7900406573bdde42afdac1acd8fc1b9dc07 Mon Sep 17 00:00:00 2001 From: Kiran Kamineni Date: Mon, 25 Nov 2019 15:48:58 -0800 Subject: Adding logging package to v2 Adding logging package to v2 This is migrated from v1 Issue-ID: MULTICLOUD-870 Change-Id: I9b74d77827475a1e1c588af7cb542f5be0cad7dc Signed-off-by: Kiran Kamineni --- src/orchestrator/internal/logutils/logger.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/orchestrator/internal/logutils/logger.go (limited to 'src/orchestrator/internal/logutils/logger.go') diff --git a/src/orchestrator/internal/logutils/logger.go b/src/orchestrator/internal/logutils/logger.go new file mode 100644 index 00000000..2e8f9969 --- /dev/null +++ b/src/orchestrator/internal/logutils/logger.go @@ -0,0 +1,28 @@ +package logutils + +import ( + log "github.com/sirupsen/logrus" +) + +//Fields is type that will be used by the calling function +type Fields map[string]interface{} + +func init() { + // Log as JSON instead of the default ASCII formatter. + log.SetFormatter(&log.JSONFormatter{}) +} + +// Error uses the fields provided and logs +func Error(msg string, fields Fields) { + log.WithFields(log.Fields(fields)).Error(msg) +} + +// Warn uses the fields provided and logs +func Warn(msg string, fields Fields) { + log.WithFields(log.Fields(fields)).Warn(msg) +} + +// Info uses the fields provided and logs +func Info(msg string, fields Fields) { + log.WithFields(log.Fields(fields)).Info(msg) +} -- cgit 1.2.3-korg