...

Source file src/github.com/jackc/pgx/v4/log/testingadapter/adapter.go

Documentation: github.com/jackc/pgx/v4/log/testingadapter

     1  // Package testingadapter provides a logger that writes to a test or benchmark
     2  // log.
     3  package testingadapter
     4  
     5  import (
     6  	"context"
     7  	"fmt"
     8  
     9  	"github.com/jackc/pgx/v4"
    10  )
    11  
    12  // TestingLogger interface defines the subset of testing.TB methods used by this
    13  // adapter.
    14  type TestingLogger interface {
    15  	Log(args ...interface{})
    16  }
    17  
    18  type Logger struct {
    19  	l TestingLogger
    20  }
    21  
    22  func NewLogger(l TestingLogger) *Logger {
    23  	return &Logger{l: l}
    24  }
    25  
    26  func (l *Logger) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) {
    27  	logArgs := make([]interface{}, 0, 2+len(data))
    28  	logArgs = append(logArgs, level, msg)
    29  	for k, v := range data {
    30  		logArgs = append(logArgs, fmt.Sprintf("%s=%v", k, v))
    31  	}
    32  	l.l.Log(logArgs...)
    33  }
    34  

View as plain text