github.com/newrelic/go-agent@v3.26.0+incompatible/_integrations/nrlogxi/v1/nrlogxi.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  // Package nrlogxi supports https://github.com/mgutz/logxi.
     5  //
     6  // Wrap your logxi Logger using nrlogxi.New to send agent log messages through
     7  // logxi.
     8  package nrlogxi
     9  
    10  import (
    11  	"github.com/mgutz/logxi/v1"
    12  	newrelic "github.com/newrelic/go-agent"
    13  	"github.com/newrelic/go-agent/internal"
    14  )
    15  
    16  func init() { internal.TrackUsage("integration", "logging", "logxi", "v1") }
    17  
    18  type shim struct {
    19  	e log.Logger
    20  }
    21  
    22  func (l *shim) Error(msg string, context map[string]interface{}) {
    23  	l.e.Error(msg, convert(context)...)
    24  }
    25  func (l *shim) Warn(msg string, context map[string]interface{}) {
    26  	l.e.Warn(msg, convert(context)...)
    27  }
    28  func (l *shim) Info(msg string, context map[string]interface{}) {
    29  	l.e.Info(msg, convert(context)...)
    30  }
    31  func (l *shim) Debug(msg string, context map[string]interface{}) {
    32  	l.e.Debug(msg, convert(context)...)
    33  }
    34  func (l *shim) DebugEnabled() bool {
    35  	return l.e.IsDebug()
    36  }
    37  
    38  func convert(c map[string]interface{}) []interface{} {
    39  	output := make([]interface{}, 0, 2*len(c))
    40  	for k, v := range c {
    41  		output = append(output, k, v)
    42  	}
    43  	return output
    44  }
    45  
    46  // New returns a newrelic.Logger which forwards agent log messages to the
    47  // provided logxi Logger.
    48  func New(l log.Logger) newrelic.Logger {
    49  	return &shim{
    50  		e: l,
    51  	}
    52  }