github.com/lulzWill/go-agent@v2.1.2+incompatible/_integrations/nrlogxi/v1/nrlogxi.go (about) 1 // Package nrlogxi forwards go-agent log messages to mgutz/logxi. If you would 2 // like to use mgutz/logxi for go-agent log messages, wrap your logxi Logger 3 // using nrlogxi.New to create a newrelic.Logger. 4 // 5 // l := log.New("newrelic") 6 // l.SetLevel(log.LevelInfo) 7 // cfg.Logger = nrlogxi.New(l) 8 // 9 package nrlogxi 10 11 import ( 12 "github.com/mgutz/logxi/v1" 13 newrelic "github.com/lulzWill/go-agent" 14 "github.com/lulzWill/go-agent/internal" 15 ) 16 17 func init() { internal.TrackUsage("integration", "logging", "logxi", "v1") } 18 19 type shim struct { 20 e log.Logger 21 } 22 23 func (l *shim) Error(msg string, context map[string]interface{}) { 24 l.e.Error(msg, convert(context)...) 25 } 26 func (l *shim) Warn(msg string, context map[string]interface{}) { 27 l.e.Warn(msg, convert(context)...) 28 } 29 func (l *shim) Info(msg string, context map[string]interface{}) { 30 l.e.Info(msg, convert(context)...) 31 } 32 func (l *shim) Debug(msg string, context map[string]interface{}) { 33 l.e.Debug(msg, convert(context)...) 34 } 35 func (l *shim) DebugEnabled() bool { 36 return l.e.IsDebug() 37 } 38 39 func convert(c map[string]interface{}) []interface{} { 40 output := make([]interface{}, 0, 2*len(c)) 41 for k, v := range c { 42 output = append(output, k, v) 43 } 44 return output 45 } 46 47 // New returns a newrelic.Logger which forwards agent log messages to the 48 // provided logxi Logger. 49 func New(l log.Logger) newrelic.Logger { 50 return &shim{ 51 e: l, 52 } 53 }