forked from newrelic/go-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrlogxi.go
49 lines (43 loc) · 1.2 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
// Package nrlogxi supports https://github.com/mgutz/logxi.
//
// Wrap your logxi Logger using nrlogxi.New to send agent log messages through
// logxi.
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,
}
}