Update split SDK to 6.0.2 to fix sync bug (#17060)
* Update split SDK to 6.0.2 to fix sync bug * Vendor and tidy
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fa2ecad0a9
Коммит
aba00a3cfd
33
vendor/github.com/splitio/go-toolkit/v4/logging/functions.go
сгенерированный
поставляемый
Обычный файл
33
vendor/github.com/splitio/go-toolkit/v4/logging/functions.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,33 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ObfuscateAPIKey obfucate part of api key
|
||||
func ObfuscateAPIKey(apikey string) string {
|
||||
obfuscationIndex := 80
|
||||
|
||||
total := len(apikey)
|
||||
charsToObfuscate := obfuscationIndex * total / 100
|
||||
toShow := (total - charsToObfuscate) / 2
|
||||
|
||||
return strings.Join([]string{apikey[:toShow], apikey[len(apikey)-toShow:]}, "...")
|
||||
}
|
||||
|
||||
// ObfuscateHTTPHeader obfuscates sensitive data into headers
|
||||
func ObfuscateHTTPHeader(headers http.Header) string {
|
||||
var re = regexp.MustCompile(`Authorization:\[Bearer ([0-9|a-z|A-Z|\s]*)\]`)
|
||||
var str = fmt.Sprint(headers)
|
||||
match := re.FindStringSubmatch(str)
|
||||
|
||||
if len(match) == 2 {
|
||||
str = strings.Replace(str, match[1], ObfuscateAPIKey(match[1]), 1)
|
||||
return fmt.Sprint("[REQUEST_HEADERS]", str, "[END_REQUEST_HEADERS]")
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
12
vendor/github.com/splitio/go-toolkit/v4/logging/interface.go
сгенерированный
поставляемый
Обычный файл
12
vendor/github.com/splitio/go-toolkit/v4/logging/interface.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,12 @@
|
||||
package logging
|
||||
|
||||
// LoggerInterface ...
|
||||
// If a custom logger object is to be used, it should comply with the following
|
||||
// interface. (Standard go-lang library log.Logger.Println method signature)
|
||||
type LoggerInterface interface {
|
||||
Error(msg ...interface{})
|
||||
Warning(msg ...interface{})
|
||||
Info(msg ...interface{})
|
||||
Debug(msg ...interface{})
|
||||
Verbose(msg ...interface{})
|
||||
}
|
||||
93
vendor/github.com/splitio/go-toolkit/v4/logging/levels.go
сгенерированный
поставляемый
Обычный файл
93
vendor/github.com/splitio/go-toolkit/v4/logging/levels.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,93 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// Standard values
|
||||
const (
|
||||
// Discard 0 value, so when can use it as "the lack of a logging level"
|
||||
_ = iota
|
||||
|
||||
// LevelError log level
|
||||
LevelError
|
||||
|
||||
// LevelWarning log level
|
||||
LevelWarning
|
||||
|
||||
// LevelInfo log level
|
||||
LevelInfo
|
||||
|
||||
// LevelDebug log level
|
||||
LevelDebug
|
||||
|
||||
// LevelVerbose log level
|
||||
LevelVerbose
|
||||
)
|
||||
|
||||
// Special values
|
||||
const (
|
||||
// LevelNone implies that NOTHING will be logged, not even errors
|
||||
LevelNone = math.MinInt32
|
||||
|
||||
// LevelAll implies that All logging levels will be recorded
|
||||
LevelAll = math.MaxInt32
|
||||
)
|
||||
|
||||
// LevelFilteredLoggerWrapper forwards log message to delegate if level is set higher than incoming message
|
||||
type LevelFilteredLoggerWrapper struct {
|
||||
level int
|
||||
delegate LoggerInterface
|
||||
}
|
||||
|
||||
// Error forwards error logging messages
|
||||
func (l *LevelFilteredLoggerWrapper) Error(is ...interface{}) {
|
||||
if l.level >= LevelError {
|
||||
l.delegate.Error(is...)
|
||||
}
|
||||
}
|
||||
|
||||
// Warning forwards warning logging messages
|
||||
func (l *LevelFilteredLoggerWrapper) Warning(is ...interface{}) {
|
||||
if l.level >= LevelWarning {
|
||||
l.delegate.Warning(is...)
|
||||
}
|
||||
}
|
||||
|
||||
// Info forwards info logging messages
|
||||
func (l *LevelFilteredLoggerWrapper) Info(is ...interface{}) {
|
||||
if l.level >= LevelInfo {
|
||||
l.delegate.Info(is...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug forwards debug logging messages
|
||||
func (l *LevelFilteredLoggerWrapper) Debug(is ...interface{}) {
|
||||
if l.level >= LevelDebug {
|
||||
l.delegate.Debug(is...)
|
||||
}
|
||||
}
|
||||
|
||||
// Verbose forwards verbose logging messages
|
||||
func (l *LevelFilteredLoggerWrapper) Verbose(is ...interface{}) {
|
||||
if l.level >= LevelVerbose {
|
||||
l.delegate.Verbose(is...)
|
||||
}
|
||||
}
|
||||
|
||||
var levels map[string]int = map[string]int{
|
||||
"ERROR": LevelError,
|
||||
"WARNING": LevelWarning,
|
||||
"INFO": LevelInfo,
|
||||
"DEBUG": LevelDebug,
|
||||
"VERBOSE": LevelVerbose,
|
||||
}
|
||||
|
||||
// Level gets current level
|
||||
func Level(level string) int {
|
||||
l, ok := levels[level]
|
||||
if !ok {
|
||||
panic("Invalid log level " + level)
|
||||
}
|
||||
return l
|
||||
}
|
||||
129
vendor/github.com/splitio/go-toolkit/v4/logging/logging.go
сгенерированный
поставляемый
Обычный файл
129
vendor/github.com/splitio/go-toolkit/v4/logging/logging.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,129 @@
|
||||
// Package logging ...
|
||||
// Handles logging within the SDK
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
skipStackFrameBase = 3 // How many stack frames to skip when logging filename
|
||||
)
|
||||
|
||||
// LoggerOptions ...
|
||||
// Struct that must be passed to the NewLogger constructor to setup a logger
|
||||
// CommonWriter and ErrorWriter can be <nil>. In that case they'll default to os.Stdout
|
||||
type LoggerOptions struct {
|
||||
LogLevel int
|
||||
ErrorWriter io.Writer
|
||||
WarningWriter io.Writer
|
||||
InfoWriter io.Writer
|
||||
DebugWriter io.Writer
|
||||
VerboseWriter io.Writer
|
||||
StandardLoggerFlags int
|
||||
Prefix string
|
||||
ExtraFramesToSkip int
|
||||
}
|
||||
|
||||
// Logger struct. Encapsulates four different loggers, each for a different "level",
|
||||
// and provides Error, Debug, Warning and Info functions, that will forward a message
|
||||
// to the appropriate logger.
|
||||
type Logger struct {
|
||||
debugLogger log.Logger
|
||||
infoLogger log.Logger
|
||||
warningLogger log.Logger
|
||||
errorLogger log.Logger
|
||||
verboseLogger log.Logger
|
||||
framesToSkip int
|
||||
}
|
||||
|
||||
// Verbose logs a message with Debug level
|
||||
func (l *Logger) Verbose(msg ...interface{}) {
|
||||
l.verboseLogger.Output(l.framesToSkip, fmt.Sprintln(msg...))
|
||||
}
|
||||
|
||||
// Debug logs a message with Debug level
|
||||
func (l *Logger) Debug(msg ...interface{}) {
|
||||
l.debugLogger.Output(l.framesToSkip, fmt.Sprintln(msg...))
|
||||
}
|
||||
|
||||
// Info logs a message with Info level
|
||||
func (l *Logger) Info(msg ...interface{}) {
|
||||
l.infoLogger.Output(l.framesToSkip, fmt.Sprintln(msg...))
|
||||
}
|
||||
|
||||
// Warning logs a message with Warning level
|
||||
func (l *Logger) Warning(msg ...interface{}) {
|
||||
l.warningLogger.Output(l.framesToSkip, fmt.Sprintln(msg...))
|
||||
}
|
||||
|
||||
// Error logs a message with Error level
|
||||
func (l *Logger) Error(msg ...interface{}) {
|
||||
l.errorLogger.Output(l.framesToSkip, fmt.Sprintln(msg...))
|
||||
}
|
||||
|
||||
func normalizeOptions(options *LoggerOptions) *LoggerOptions {
|
||||
var toRet *LoggerOptions
|
||||
if options == nil {
|
||||
toRet = &LoggerOptions{}
|
||||
} else {
|
||||
toRet = options
|
||||
}
|
||||
|
||||
if toRet.DebugWriter == nil {
|
||||
toRet.DebugWriter = os.Stdout
|
||||
}
|
||||
|
||||
if toRet.ErrorWriter == nil {
|
||||
toRet.ErrorWriter = os.Stdout
|
||||
}
|
||||
|
||||
if toRet.InfoWriter == nil {
|
||||
toRet.InfoWriter = os.Stdout
|
||||
}
|
||||
|
||||
if toRet.VerboseWriter == nil {
|
||||
toRet.VerboseWriter = os.Stdout
|
||||
}
|
||||
|
||||
if toRet.WarningWriter == nil {
|
||||
toRet.WarningWriter = os.Stdout
|
||||
}
|
||||
|
||||
if toRet.StandardLoggerFlags == 0 {
|
||||
toRet.StandardLoggerFlags = log.Ldate | log.Ltime
|
||||
}
|
||||
|
||||
switch toRet.LogLevel {
|
||||
case LevelAll, LevelDebug, LevelError, LevelInfo, LevelNone, LevelVerbose, LevelWarning:
|
||||
default:
|
||||
toRet.LogLevel = LevelError
|
||||
}
|
||||
return toRet
|
||||
}
|
||||
|
||||
// NewLogger instantiates a new Logger instance. Requires a pointer to a LoggerOptions struct to be passed.
|
||||
func NewLogger(options *LoggerOptions) LoggerInterface {
|
||||
|
||||
options = normalizeOptions(options)
|
||||
prefix := ""
|
||||
if options.Prefix != "" {
|
||||
prefix = fmt.Sprintf("%s - ", options.Prefix)
|
||||
}
|
||||
logger := &Logger{
|
||||
debugLogger: *log.New(options.DebugWriter, fmt.Sprintf("%sDEBUG - ", prefix), options.StandardLoggerFlags),
|
||||
infoLogger: *log.New(options.InfoWriter, fmt.Sprintf("%sINFO - ", prefix), options.StandardLoggerFlags),
|
||||
warningLogger: *log.New(options.WarningWriter, fmt.Sprintf("%sWARNING - ", prefix), options.StandardLoggerFlags),
|
||||
errorLogger: *log.New(options.ErrorWriter, fmt.Sprintf("%sERROR - ", prefix), options.StandardLoggerFlags),
|
||||
verboseLogger: *log.New(options.VerboseWriter, fmt.Sprintf("%sVERBOSE - ", prefix), options.StandardLoggerFlags),
|
||||
framesToSkip: 3 + options.ExtraFramesToSkip,
|
||||
}
|
||||
|
||||
return &LevelFilteredLoggerWrapper{
|
||||
delegate: logger,
|
||||
level: options.LogLevel,
|
||||
}
|
||||
}
|
||||
106
vendor/github.com/splitio/go-toolkit/v4/logging/rotate.go
сгенерированный
поставляемый
Обычный файл
106
vendor/github.com/splitio/go-toolkit/v4/logging/rotate.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,106 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// FileRotateOptions struct to configure FileRotate
|
||||
type FileRotateOptions struct {
|
||||
MaxBytes int64
|
||||
BackupCount int
|
||||
Path string
|
||||
}
|
||||
|
||||
// FileRotate rotates a log file at MaxBytes
|
||||
type FileRotate struct {
|
||||
fl *os.File
|
||||
fm *sync.Mutex
|
||||
options *FileRotateOptions
|
||||
}
|
||||
|
||||
// NewFileRotate returns a pointer to a FileRotate instance
|
||||
func NewFileRotate(opt *FileRotateOptions) (*FileRotate, error) {
|
||||
|
||||
fileWriter, err := os.OpenFile(opt.Path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fl := &FileRotate{fl: fileWriter, fm: &sync.Mutex{}, options: opt}
|
||||
return fl, nil
|
||||
}
|
||||
|
||||
func (f *FileRotate) shouldRotate(bytesToAdd int64) bool {
|
||||
fi, err := f.fl.Stat()
|
||||
if err != nil {
|
||||
fmt.Println("Error getting stats of file")
|
||||
return false
|
||||
}
|
||||
|
||||
if fi.Size()+bytesToAdd >= f.options.MaxBytes {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (f *FileRotate) rotate() error {
|
||||
|
||||
f.fl.Close()
|
||||
|
||||
for i := f.options.BackupCount - 1; i >= 0; i-- {
|
||||
var currentLog string
|
||||
if i == 0 {
|
||||
currentLog = f.options.Path
|
||||
} else {
|
||||
currentLog = f.options.Path + "." + strconv.Itoa(i)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(currentLog); err == nil {
|
||||
rotateLog := f.options.Path + "." + strconv.Itoa(i+1)
|
||||
err := os.Rename(currentLog, rotateLog)
|
||||
if err != nil {
|
||||
fmt.Printf("Error rotating log file: %s \n", err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var err error
|
||||
f.fl, err = os.OpenFile(f.options.Path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reopening log file: %s \n", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FileRotate) write(p []byte) (n int, err error) {
|
||||
f.fm.Lock()
|
||||
if f.shouldRotate(int64(len(p))) {
|
||||
f.rotate()
|
||||
}
|
||||
|
||||
n, err = f.fl.Write(p)
|
||||
f.fm.Unlock()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error writing in rotated log file", f.options.Path)
|
||||
return n, err
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// Write writes async the log message
|
||||
func (f *FileRotate) Write(p []byte) (n int, err error) {
|
||||
dst := make([]byte, len(p))
|
||||
copy(dst, p)
|
||||
go f.write(dst)
|
||||
return len(p), nil
|
||||
}
|
||||
Ссылка в новой задаче
Block a user