4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-03 22:27:44 +00:00

Update dependencies/vendor (#1659)

This commit is contained in:
Wim
2021-12-12 00:05:15 +01:00
committed by GitHub
parent 658bdd9faa
commit 3893a035be
214 changed files with 8892 additions and 5650 deletions

28
vendor/github.com/mattermost/logr/v2/buffer.go generated vendored Normal file
View File

@ -0,0 +1,28 @@
package logr
import (
"bytes"
"sync"
)
// Buffer provides a thread-safe buffer useful for logging to memory in unit tests.
type Buffer struct {
buf bytes.Buffer
mux sync.Mutex
}
func (b *Buffer) Read(p []byte) (n int, err error) {
b.mux.Lock()
defer b.mux.Unlock()
return b.buf.Read(p)
}
func (b *Buffer) Write(p []byte) (n int, err error) {
b.mux.Lock()
defer b.mux.Unlock()
return b.buf.Write(p)
}
func (b *Buffer) String() string {
b.mux.Lock()
defer b.mux.Unlock()
return b.buf.String()
}

View File

@ -31,8 +31,8 @@ type TargetFactory func(targetType string, options json.RawMessage) (logr.Target
type FormatterFactory func(format string, options json.RawMessage) (logr.Formatter, error)
type Factories struct {
targetFactory TargetFactory // can be nil
formatterFactory FormatterFactory // can be nil
TargetFactory TargetFactory // can be nil
FormatterFactory FormatterFactory // can be nil
}
var removeAll = func(ti logr.TargetInfo) bool { return true }
@ -56,7 +56,7 @@ func ConfigureTargets(lgr *logr.Logr, config map[string]TargetCfg, factories *Fa
}
for name, tcfg := range config {
target, err := newTarget(tcfg.Type, tcfg.Options, factories.targetFactory)
target, err := newTarget(tcfg.Type, tcfg.Options, factories.TargetFactory)
if err != nil {
return fmt.Errorf("error creating log target %s: %w", name, err)
}
@ -65,7 +65,7 @@ func ConfigureTargets(lgr *logr.Logr, config map[string]TargetCfg, factories *Fa
continue
}
formatter, err := newFormatter(tcfg.Format, tcfg.FormatOptions, factories.formatterFactory)
formatter, err := newFormatter(tcfg.Format, tcfg.FormatOptions, factories.FormatterFactory)
if err != nil {
return fmt.Errorf("error creating formatter for log target %s: %w", name, err)
}

View File

@ -15,7 +15,7 @@ var (
Space = []byte{' '}
Newline = []byte{'\n'}
Quote = []byte{'"'}
Colon = []byte{'"'}
Colon = []byte{':'}
)
// LogCloner is implemented by `Any` types that require a clone to be provided

View File

@ -11,6 +11,7 @@ type StdFilter struct {
// is enabled for this filter.
func (lt StdFilter) GetEnabledLevel(level Level) (Level, bool) {
enabled := level.ID <= lt.Lvl.ID
stackTrace := level.ID <= lt.Stacktrace.ID
var levelEnabled Level
if enabled {
@ -33,6 +34,11 @@ func (lt StdFilter) GetEnabledLevel(level Level) (Level, bool) {
levelEnabled = level
}
}
if stackTrace {
levelEnabled.Stacktrace = true
}
return levelEnabled, enabled
}

View File

@ -117,3 +117,81 @@ func (s Sugar) Fatalf(format string, args ...interface{}) {
func (s Sugar) Panicf(format string, args ...interface{}) {
s.Logf(Panic, format, args...)
}
//
// K/V style
//
// With returns a new Sugar logger with the specified key/value pairs added to the
// fields list.
func (s Sugar) With(keyValuePairs ...interface{}) Sugar {
return s.logger.With(s.argsToFields(keyValuePairs)...).Sugar()
}
// Tracew outputs at trace level with the specified key/value pairs converted to fields.
func (s Sugar) Tracew(msg string, keyValuePairs ...interface{}) {
s.logger.Log(Trace, msg, s.argsToFields(keyValuePairs)...)
}
// Debugw outputs at debug level with the specified key/value pairs converted to fields.
func (s Sugar) Debugw(msg string, keyValuePairs ...interface{}) {
s.logger.Log(Debug, msg, s.argsToFields(keyValuePairs)...)
}
// Infow outputs at info level with the specified key/value pairs converted to fields.
func (s Sugar) Infow(msg string, keyValuePairs ...interface{}) {
s.logger.Log(Info, msg, s.argsToFields(keyValuePairs)...)
}
// Warnw outputs at warn level with the specified key/value pairs converted to fields.
func (s Sugar) Warnw(msg string, keyValuePairs ...interface{}) {
s.logger.Log(Warn, msg, s.argsToFields(keyValuePairs)...)
}
// Errorw outputs at error level with the specified key/value pairs converted to fields.
func (s Sugar) Errorw(msg string, keyValuePairs ...interface{}) {
s.logger.Log(Error, msg, s.argsToFields(keyValuePairs)...)
}
// Fatalw outputs at fatal level with the specified key/value pairs converted to fields.
func (s Sugar) Fatalw(msg string, keyValuePairs ...interface{}) {
s.logger.Log(Fatal, msg, s.argsToFields(keyValuePairs)...)
}
// Panicw outputs at panic level with the specified key/value pairs converted to fields.
func (s Sugar) Panicw(msg string, keyValuePairs ...interface{}) {
s.logger.Log(Panic, msg, s.argsToFields(keyValuePairs)...)
}
// argsToFields converts an array of args, possibly containing name/value pairs
// into a []Field.
func (s Sugar) argsToFields(keyValuePairs []interface{}) []Field {
if len(keyValuePairs) == 0 {
return nil
}
fields := make([]Field, 0, len(keyValuePairs))
count := len(keyValuePairs)
for i := 0; i < count; {
if fld, ok := keyValuePairs[i].(Field); ok {
fields = append(fields, fld)
i++
continue
}
if i == count-1 {
s.logger.Error("invalid key/value pair", Any("arg", keyValuePairs[i]))
break
}
// we should have a key/value pair now. The key must be a string.
if key, ok := keyValuePairs[i].(string); !ok {
s.logger.Error("invalid key for key/value pair", Int("pos", i))
} else {
fields = append(fields, Any(key, keyValuePairs[i+1]))
}
i += 2
}
return fields
}

View File

@ -0,0 +1,72 @@
package targets
import (
"strings"
"sync"
"testing"
"github.com/mattermost/logr/v2"
"github.com/mattermost/logr/v2/formatters"
)
// Testing is a simple log target that writes to a (*testing.T) log.
type Testing struct {
mux sync.Mutex
t *testing.T
}
func NewTestingTarget(t *testing.T) *Testing {
return &Testing{
t: t,
}
}
// Init is called once to initialize the target.
func (tt *Testing) Init() error {
return nil
}
// Write outputs bytes to this file target.
func (tt *Testing) Write(p []byte, rec *logr.LogRec) (int, error) {
tt.mux.Lock()
defer tt.mux.Unlock()
if tt.t != nil {
s := strings.TrimSpace(string(p))
tt.t.Log(s)
}
return len(p), nil
}
// Shutdown is called once to free/close any resources.
// Target queue is already drained when this is called.
func (tt *Testing) Shutdown() error {
tt.mux.Lock()
defer tt.mux.Unlock()
tt.t = nil
return nil
}
// CreateTestLogger creates a logger for unit tests. Log records are output to `(*testing.T).Log`.
// A new logger is returned along with a method to shutdown the new logger.
func CreateTestLogger(t *testing.T, levels ...logr.Level) (logger logr.Logger, shutdown func() error) {
lgr, _ := logr.New()
filter := logr.NewCustomFilter(levels...)
formatter := &formatters.Plain{EnableCaller: true}
target := NewTestingTarget(t)
if err := lgr.AddTarget(target, "test", filter, formatter, 1000); err != nil {
t.Fail()
}
shutdown = func() error {
err := lgr.Shutdown()
if err != nil {
target.mux.Lock()
target.t.Error("error shutting down test logger", err)
target.mux.Unlock()
}
return err
}
return lgr.NewLogger(), shutdown
}