d32f8c458b28e13502a5ab778a1901984819a3fc
[icn/sdwan.git] /
1 package logutils\r
2 \r
3 import (\r
4         "github.com/open-ness/EMCO/src/orchestrator/pkg/infra/config"\r
5         log "github.com/sirupsen/logrus"\r
6         "strings"\r
7 )\r
8 \r
9 //Fields is type that will be used by the calling function\r
10 type Fields map[string]interface{}\r
11 \r
12 func init() {\r
13         // Log as JSON instead of the default ASCII formatter.\r
14         log.SetFormatter(&log.JSONFormatter{})\r
15         if strings.EqualFold(config.GetConfiguration().LogLevel, "warn") {\r
16                 log.SetLevel(log.WarnLevel)\r
17 \r
18         }\r
19         if strings.EqualFold(config.GetConfiguration().LogLevel, "info") {\r
20                 log.SetLevel(log.InfoLevel)\r
21         }\r
22 }\r
23 \r
24 // Error uses the fields provided and logs\r
25 func Error(msg string, fields Fields) {\r
26         log.WithFields(log.Fields(fields)).Error(msg)\r
27 }\r
28 \r
29 // Warn uses the fields provided and logs\r
30 func Warn(msg string, fields Fields) {\r
31         log.WithFields(log.Fields(fields)).Warn(msg)\r
32 }\r
33 \r
34 // Info uses the fields provided and logs\r
35 func Info(msg string, fields Fields) {\r
36         log.WithFields(log.Fields(fields)).Info(msg)\r
37 }\r