aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/smithy-go/logging
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-12-12 21:55:07 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-12-12 22:25:10 +0300
commit4967f99474a4040ba150eb04995de06342252718 (patch)
treec9c118836513a8fab6e9fcfb25be5d404338bca7 /vendor/github.com/aws/smithy-go/logging
parent2ce9cccb9b0bdd4cd7a3491dc5cbf8687cda51de (diff)
downloadydb-4967f99474a4040ba150eb04995de06342252718.tar.gz
YQ Connector: prepare code base for S3 integration
1. Кодовая база Коннектора переписана с помощью Go дженериков так, чтобы добавление нового источника данных (в частности S3 + csv) максимально переиспользовало имеющийся код (чтобы сохранялась логика нарезания на блоки данных, учёт трафика и пр.) 2. API Connector расширено для работы с S3, но ещё пока не протестировано.
Diffstat (limited to 'vendor/github.com/aws/smithy-go/logging')
-rw-r--r--vendor/github.com/aws/smithy-go/logging/gotest/ya.make5
-rw-r--r--vendor/github.com/aws/smithy-go/logging/logger.go82
-rw-r--r--vendor/github.com/aws/smithy-go/logging/logger_test.go71
-rw-r--r--vendor/github.com/aws/smithy-go/logging/ya.make15
4 files changed, 173 insertions, 0 deletions
diff --git a/vendor/github.com/aws/smithy-go/logging/gotest/ya.make b/vendor/github.com/aws/smithy-go/logging/gotest/ya.make
new file mode 100644
index 0000000000..d1c8359ff3
--- /dev/null
+++ b/vendor/github.com/aws/smithy-go/logging/gotest/ya.make
@@ -0,0 +1,5 @@
+GO_TEST_FOR(vendor/github.com/aws/smithy-go/logging)
+
+LICENSE(Apache-2.0)
+
+END()
diff --git a/vendor/github.com/aws/smithy-go/logging/logger.go b/vendor/github.com/aws/smithy-go/logging/logger.go
new file mode 100644
index 0000000000..2071924bd3
--- /dev/null
+++ b/vendor/github.com/aws/smithy-go/logging/logger.go
@@ -0,0 +1,82 @@
+package logging
+
+import (
+ "context"
+ "io"
+ "log"
+)
+
+// Classification is the type of the log entry's classification name.
+type Classification string
+
+// Set of standard classifications that can be used by clients and middleware
+const (
+ Warn Classification = "WARN"
+ Debug Classification = "DEBUG"
+)
+
+// Logger is an interface for logging entries at certain classifications.
+type Logger interface {
+ // Logf is expected to support the standard fmt package "verbs".
+ Logf(classification Classification, format string, v ...interface{})
+}
+
+// LoggerFunc is a wrapper around a function to satisfy the Logger interface.
+type LoggerFunc func(classification Classification, format string, v ...interface{})
+
+// Logf delegates the logging request to the wrapped function.
+func (f LoggerFunc) Logf(classification Classification, format string, v ...interface{}) {
+ f(classification, format, v...)
+}
+
+// ContextLogger is an optional interface a Logger implementation may expose that provides
+// the ability to create context aware log entries.
+type ContextLogger interface {
+ WithContext(context.Context) Logger
+}
+
+// WithContext will pass the provided context to logger if it implements the ContextLogger interface and return the resulting
+// logger. Otherwise the logger will be returned as is. As a special case if a nil logger is provided, a Nop logger will
+// be returned to the caller.
+func WithContext(ctx context.Context, logger Logger) Logger {
+ if logger == nil {
+ return Nop{}
+ }
+
+ cl, ok := logger.(ContextLogger)
+ if !ok {
+ return logger
+ }
+
+ return cl.WithContext(ctx)
+}
+
+// Nop is a Logger implementation that simply does not perform any logging.
+type Nop struct{}
+
+// Logf simply returns without performing any action
+func (n Nop) Logf(Classification, string, ...interface{}) {
+ return
+}
+
+// StandardLogger is a Logger implementation that wraps the standard library logger, and delegates logging to it's
+// Printf method.
+type StandardLogger struct {
+ Logger *log.Logger
+}
+
+// Logf logs the given classification and message to the underlying logger.
+func (s StandardLogger) Logf(classification Classification, format string, v ...interface{}) {
+ if len(classification) != 0 {
+ format = string(classification) + " " + format
+ }
+
+ s.Logger.Printf(format, v...)
+}
+
+// NewStandardLogger returns a new StandardLogger
+func NewStandardLogger(writer io.Writer) *StandardLogger {
+ return &StandardLogger{
+ Logger: log.New(writer, "SDK ", log.LstdFlags),
+ }
+}
diff --git a/vendor/github.com/aws/smithy-go/logging/logger_test.go b/vendor/github.com/aws/smithy-go/logging/logger_test.go
new file mode 100644
index 0000000000..fd4facc24c
--- /dev/null
+++ b/vendor/github.com/aws/smithy-go/logging/logger_test.go
@@ -0,0 +1,71 @@
+package logging_test
+
+import (
+ "bytes"
+ "context"
+ "fmt"
+ "regexp"
+ "testing"
+
+ "github.com/aws/smithy-go/logging"
+)
+
+func TestNewStandardLogger(t *testing.T) {
+ var buffer bytes.Buffer
+ logger := logging.NewStandardLogger(&buffer)
+ const matchStr = `SDK \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} %s foo bar baz\n`
+
+ logger.Logf(logging.Debug, "foo %s baz", "bar")
+ match := regexp.MustCompile(fmt.Sprintf(matchStr, "DEBUG"))
+ if !match.Match(buffer.Bytes()) {
+ t.Error("log entry did not match expected")
+ }
+
+ logger.Logf(logging.Warn, "foo %s baz", "bar")
+ match = regexp.MustCompile(fmt.Sprintf(matchStr, "WARN"))
+ if !match.Match(buffer.Bytes()) {
+ t.Error("log entry did not match expected")
+ }
+}
+
+func TestNop(t *testing.T) {
+ logging.Nop{}.Logf(logging.Debug, "foo")
+}
+
+func TestWithContext(t *testing.T) {
+ l := &mockContextLogger{}
+ expectContextStrValue := "bar"
+ nl := logging.WithContext(context.WithValue(context.Background(), "foo", expectContextStrValue), l)
+
+ v, ok := nl.(*mockContextLogger)
+ if !ok {
+ t.Fatalf("expect %T, got %T", &mockContextLogger{}, nl)
+ }
+
+ if v.ctx == nil {
+ t.Fatal("expect context to not be nil")
+ }
+
+ ctxValue := v.ctx.Value("foo")
+ str, ok := ctxValue.(string)
+ if !ok {
+ t.Fatalf("expect string, got %T", str)
+ }
+
+ if str != expectContextStrValue {
+ t.Errorf("expect %v, got %v", expectContextStrValue, str)
+ }
+}
+
+type mockContextLogger struct {
+ ctx context.Context
+}
+
+func (m mockContextLogger) WithContext(ctx context.Context) logging.Logger {
+ m.ctx = ctx
+ return &m
+}
+
+func (m mockContextLogger) Logf(level logging.Classification, format string, v ...interface{}) {
+ return
+}
diff --git a/vendor/github.com/aws/smithy-go/logging/ya.make b/vendor/github.com/aws/smithy-go/logging/ya.make
new file mode 100644
index 0000000000..4ff70a2b29
--- /dev/null
+++ b/vendor/github.com/aws/smithy-go/logging/ya.make
@@ -0,0 +1,15 @@
+GO_LIBRARY()
+
+LICENSE(Apache-2.0)
+
+SRCS(
+ logger.go
+)
+
+GO_XTEST_SRCS(logger_test.go)
+
+END()
+
+RECURSE(
+ gotest
+)