github.com/lulzWill/go-agent@v2.1.2+incompatible/_integrations/nrlogrus/nrlogrus.go (about) 1 // Package nrlogrus forwards go-agent log messages to logrus. If you are using 2 // logrus for your application and would like the go-agent log messages to end 3 // up in the same place, modify your config as follows: 4 // 5 // cfg.Logger = nrlogrus.StandardLogger() 6 // 7 // Only logrus' StandardLogger is supported since there is no method (as of July 8 // 2016) to get the level of a logrus.Logger. See 9 // https://github.com/sirupsen/logrus/issues/241 10 package nrlogrus 11 12 import ( 13 newrelic "github.com/lulzWill/go-agent" 14 "github.com/lulzWill/go-agent/internal" 15 "github.com/sirupsen/logrus" 16 ) 17 18 func init() { internal.TrackUsage("integration", "logging", "logrus") } 19 20 type shim struct{ e *logrus.Entry } 21 22 func (s *shim) Error(msg string, c map[string]interface{}) { 23 s.e.WithFields(c).Error(msg) 24 } 25 func (s *shim) Warn(msg string, c map[string]interface{}) { 26 s.e.WithFields(c).Warn(msg) 27 } 28 func (s *shim) Info(msg string, c map[string]interface{}) { 29 s.e.WithFields(c).Info(msg) 30 } 31 func (s *shim) Debug(msg string, c map[string]interface{}) { 32 s.e.WithFields(c).Info(msg) 33 } 34 func (s *shim) DebugEnabled() bool { 35 lvl := logrus.GetLevel() 36 return lvl >= logrus.DebugLevel 37 } 38 39 // StandardLogger returns a newrelic.Logger which forwards agent log messages to 40 // the logrus package-level exported logger. 41 func StandardLogger() newrelic.Logger { 42 return &shim{ 43 e: logrus.WithFields(logrus.Fields{ 44 "component": "newrelic", 45 }), 46 } 47 }