Remove dead legacy logger code.
parent
a769916ea2
commit
54b87505a3
|
@ -16,86 +16,15 @@ package clientv3
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
|
||||
"go.etcd.io/etcd/pkg/v3/logutil"
|
||||
|
||||
"google.golang.org/grpc/grpclog"
|
||||
)
|
||||
|
||||
var (
|
||||
lgMu sync.RWMutex
|
||||
lg logutil.Logger
|
||||
)
|
||||
|
||||
type settableLogger struct {
|
||||
l grpclog.LoggerV2
|
||||
mu sync.RWMutex
|
||||
}
|
||||
|
||||
func init() {
|
||||
// disable client side logs by default
|
||||
lg = &settableLogger{}
|
||||
SetLogger(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
|
||||
}
|
||||
|
||||
// SetLogger sets client-side Logger.
|
||||
func SetLogger(l grpclog.LoggerV2) {
|
||||
lgMu.Lock()
|
||||
lg = logutil.NewLogger(l)
|
||||
// override grpclog so that any changes happen with locking
|
||||
grpclog.SetLoggerV2(lg)
|
||||
lgMu.Unlock()
|
||||
}
|
||||
|
||||
// GetLogger returns the current logutil.Logger.
|
||||
func GetLogger() logutil.Logger {
|
||||
lgMu.RLock()
|
||||
l := lg
|
||||
lgMu.RUnlock()
|
||||
return l
|
||||
}
|
||||
|
||||
// NewLogger returns a new Logger with logutil.Logger.
|
||||
func NewLogger(gl grpclog.LoggerV2) logutil.Logger {
|
||||
return &settableLogger{l: gl}
|
||||
}
|
||||
|
||||
func (s *settableLogger) get() grpclog.LoggerV2 {
|
||||
s.mu.RLock()
|
||||
l := s.l
|
||||
s.mu.RUnlock()
|
||||
return l
|
||||
}
|
||||
|
||||
// implement the grpclog.LoggerV2 interface
|
||||
|
||||
func (s *settableLogger) Info(args ...interface{}) { s.get().Info(args...) }
|
||||
func (s *settableLogger) Infof(format string, args ...interface{}) { s.get().Infof(format, args...) }
|
||||
func (s *settableLogger) Infoln(args ...interface{}) { s.get().Infoln(args...) }
|
||||
func (s *settableLogger) Warning(args ...interface{}) { s.get().Warning(args...) }
|
||||
func (s *settableLogger) Warningf(format string, args ...interface{}) {
|
||||
s.get().Warningf(format, args...)
|
||||
}
|
||||
func (s *settableLogger) Warningln(args ...interface{}) { s.get().Warningln(args...) }
|
||||
func (s *settableLogger) Error(args ...interface{}) { s.get().Error(args...) }
|
||||
func (s *settableLogger) Errorf(format string, args ...interface{}) {
|
||||
s.get().Errorf(format, args...)
|
||||
}
|
||||
func (s *settableLogger) Errorln(args ...interface{}) { s.get().Errorln(args...) }
|
||||
func (s *settableLogger) Fatal(args ...interface{}) { s.get().Fatal(args...) }
|
||||
func (s *settableLogger) Fatalf(format string, args ...interface{}) { s.get().Fatalf(format, args...) }
|
||||
func (s *settableLogger) Fatalln(args ...interface{}) { s.get().Fatalln(args...) }
|
||||
func (s *settableLogger) Print(args ...interface{}) { s.get().Info(args...) }
|
||||
func (s *settableLogger) Printf(format string, args ...interface{}) { s.get().Infof(format, args...) }
|
||||
func (s *settableLogger) Println(args ...interface{}) { s.get().Infoln(args...) }
|
||||
func (s *settableLogger) V(l int) bool { return s.get().V(l) }
|
||||
func (s *settableLogger) Lvl(lvl int) grpclog.LoggerV2 {
|
||||
s.mu.RLock()
|
||||
l := s.l
|
||||
s.mu.RUnlock()
|
||||
if l.V(lvl) {
|
||||
return s
|
||||
}
|
||||
return logutil.NewDiscardLogger()
|
||||
grpclog.SetLoggerV2(l)
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
// Copyright 2018 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package logutil
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"google.golang.org/grpc/grpclog"
|
||||
)
|
||||
|
||||
// assert that "discardLogger" satisfy "Logger" interface
|
||||
var _ Logger = &discardLogger{}
|
||||
|
||||
// NewDiscardLogger returns a new Logger that discards everything except "fatal".
|
||||
func NewDiscardLogger() Logger { return &discardLogger{} }
|
||||
|
||||
type discardLogger struct{}
|
||||
|
||||
func (l *discardLogger) Info(args ...interface{}) {}
|
||||
func (l *discardLogger) Infoln(args ...interface{}) {}
|
||||
func (l *discardLogger) Infof(format string, args ...interface{}) {}
|
||||
func (l *discardLogger) Warning(args ...interface{}) {}
|
||||
func (l *discardLogger) Warningln(args ...interface{}) {}
|
||||
func (l *discardLogger) Warningf(format string, args ...interface{}) {}
|
||||
func (l *discardLogger) Error(args ...interface{}) {}
|
||||
func (l *discardLogger) Errorln(args ...interface{}) {}
|
||||
func (l *discardLogger) Errorf(format string, args ...interface{}) {}
|
||||
func (l *discardLogger) Fatal(args ...interface{}) { log.Fatal(args...) }
|
||||
func (l *discardLogger) Fatalln(args ...interface{}) { log.Fatalln(args...) }
|
||||
func (l *discardLogger) Fatalf(format string, args ...interface{}) { log.Fatalf(format, args...) }
|
||||
func (l *discardLogger) V(lvl int) bool {
|
||||
return false
|
||||
}
|
||||
func (l *discardLogger) Lvl(lvl int) grpclog.LoggerV2 { return l }
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright 2018 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package logutil
|
||||
|
||||
import "google.golang.org/grpc/grpclog"
|
||||
|
||||
// Logger defines logging interface.
|
||||
// TODO: deprecate in v3.5.
|
||||
type Logger interface {
|
||||
grpclog.LoggerV2
|
||||
|
||||
// Lvl returns logger if logger's verbosity level >= "lvl".
|
||||
// Otherwise, logger that discards everything.
|
||||
Lvl(lvl int) grpclog.LoggerV2
|
||||
}
|
||||
|
||||
// assert that "defaultLogger" satisfy "Logger" interface
|
||||
var _ Logger = &defaultLogger{}
|
||||
|
||||
// NewLogger wraps "grpclog.LoggerV2" that implements "Logger" interface.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// var defaultLogger Logger
|
||||
// g := grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4)
|
||||
// defaultLogger = NewLogger(g)
|
||||
//
|
||||
func NewLogger(g grpclog.LoggerV2) Logger { return &defaultLogger{g: g} }
|
||||
|
||||
type defaultLogger struct {
|
||||
g grpclog.LoggerV2
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Info(args ...interface{}) { l.g.Info(args...) }
|
||||
func (l *defaultLogger) Infoln(args ...interface{}) { l.g.Info(args...) }
|
||||
func (l *defaultLogger) Infof(format string, args ...interface{}) { l.g.Infof(format, args...) }
|
||||
func (l *defaultLogger) Warning(args ...interface{}) { l.g.Warning(args...) }
|
||||
func (l *defaultLogger) Warningln(args ...interface{}) { l.g.Warning(args...) }
|
||||
func (l *defaultLogger) Warningf(format string, args ...interface{}) { l.g.Warningf(format, args...) }
|
||||
func (l *defaultLogger) Error(args ...interface{}) { l.g.Error(args...) }
|
||||
func (l *defaultLogger) Errorln(args ...interface{}) { l.g.Error(args...) }
|
||||
func (l *defaultLogger) Errorf(format string, args ...interface{}) { l.g.Errorf(format, args...) }
|
||||
func (l *defaultLogger) Fatal(args ...interface{}) { l.g.Fatal(args...) }
|
||||
func (l *defaultLogger) Fatalln(args ...interface{}) { l.g.Fatal(args...) }
|
||||
func (l *defaultLogger) Fatalf(format string, args ...interface{}) { l.g.Fatalf(format, args...) }
|
||||
func (l *defaultLogger) V(lvl int) bool { return l.g.V(lvl) }
|
||||
func (l *defaultLogger) Lvl(lvl int) grpclog.LoggerV2 {
|
||||
if l.g.V(lvl) {
|
||||
return l
|
||||
}
|
||||
return &discardLogger{}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
// Copyright 2017 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package logutil_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"go.etcd.io/etcd/pkg/v3/logutil"
|
||||
|
||||
"google.golang.org/grpc/grpclog"
|
||||
)
|
||||
|
||||
func TestLogger(t *testing.T) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
l := logutil.NewLogger(grpclog.NewLoggerV2WithVerbosity(buf, buf, buf, 10))
|
||||
l.Infof("hello world!")
|
||||
if !strings.Contains(buf.String(), "hello world!") {
|
||||
t.Fatalf("expected 'hello world!', got %q", buf.String())
|
||||
}
|
||||
buf.Reset()
|
||||
|
||||
l.Lvl(10).Infof("Level 10")
|
||||
l.Lvl(30).Infof("Level 30")
|
||||
if !strings.Contains(buf.String(), "Level 10") {
|
||||
t.Fatalf("expected 'Level 10', got %q", buf.String())
|
||||
}
|
||||
if strings.Contains(buf.String(), "Level 30") {
|
||||
t.Fatalf("unexpected 'Level 30', got %q", buf.String())
|
||||
}
|
||||
buf.Reset()
|
||||
|
||||
l = logutil.NewLogger(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
|
||||
l.Infof("ignore this")
|
||||
if len(buf.Bytes()) > 0 {
|
||||
t.Fatalf("unexpected logs %q", buf.String())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue