aboutsummaryrefslogtreecommitdiffstats
path: root/src/orchestrator/pkg/infra/logutils/logger.go
blob: 209114a3a3bebab865e8a6cf7b52e044aabfbc78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
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
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)
}