forked from newrelic/go-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nrlogxi.go
53 lines (47 loc) · 1.35 KB
/
nrlogxi.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Package nrlogxi forwards go-agent log messages to mgutz/logxi. If you would
// like to use mgutz/logxi for go-agent log messages, wrap your logxi Logger
// using nrlogxi.New to create a newrelic.Logger.
//
// l := log.New("newrelic")
// l.SetLevel(log.LevelInfo)
// cfg.Logger = nrlogxi.New(l)
//
package nrlogxi
import (
"github.com/mgutz/logxi/v1"
newrelic "github.com/newrelic/go-agent"
"github.com/newrelic/go-agent/internal"
)
func init() { internal.TrackUsage("integration", "logging", "logxi", "v1") }
type shim struct {
e log.Logger
}
func (l *shim) Error(msg string, context map[string]interface{}) {
l.e.Error(msg, convert(context)...)
}
func (l *shim) Warn(msg string, context map[string]interface{}) {
l.e.Warn(msg, convert(context)...)
}
func (l *shim) Info(msg string, context map[string]interface{}) {
l.e.Info(msg, convert(context)...)
}
func (l *shim) Debug(msg string, context map[string]interface{}) {
l.e.Debug(msg, convert(context)...)
}
func (l *shim) DebugEnabled() bool {
return l.e.IsDebug()
}
func convert(c map[string]interface{}) []interface{} {
output := make([]interface{}, 0, 2*len(c))
for k, v := range c {
output = append(output, k, v)
}
return output
}
// New returns a newrelic.Logger which forwards agent log messages to the
// provided logxi Logger.
func New(l log.Logger) newrelic.Logger {
return &shim{
e: l,
}
}