pkg/logutil: move "pkg/logger" to "logutil"

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee 2018-03-07 10:45:29 -08:00
parent 89292affaa
commit 82ee796aa4
8 changed files with 16 additions and 21 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package logger package logutil
import ( import (
"log" "log"

View File

@ -12,5 +12,5 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package logger implements various logging utilities. // Package logutil includes utilities to facilitate logging.
package logger package logutil

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package logger package logutil
import "google.golang.org/grpc/grpclog" import "google.golang.org/grpc/grpclog"
@ -28,7 +28,7 @@ type Logger interface {
// assert that "defaultLogger" satisfy "Logger" interface // assert that "defaultLogger" satisfy "Logger" interface
var _ Logger = &defaultLogger{} var _ Logger = &defaultLogger{}
// New wraps "grpclog.LoggerV2" that implements "Logger" interface. // NewLogger wraps "grpclog.LoggerV2" that implements "Logger" interface.
// //
// For example: // For example:
// //
@ -36,7 +36,7 @@ var _ Logger = &defaultLogger{}
// g := grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4) // g := grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4)
// defaultLogger = New(g) // defaultLogger = New(g)
// //
func New(g grpclog.LoggerV2) Logger { return &defaultLogger{g: g} } func NewLogger(g grpclog.LoggerV2) Logger { return &defaultLogger{g: g} }
type defaultLogger struct { type defaultLogger struct {
g grpclog.LoggerV2 g grpclog.LoggerV2

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package logger_test package logutil_test
import ( import (
"bytes" "bytes"
@ -20,7 +20,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/coreos/etcd/pkg/logger" "github.com/coreos/etcd/pkg/logutil"
"google.golang.org/grpc/grpclog" "google.golang.org/grpc/grpclog"
) )
@ -28,7 +28,7 @@ import (
func TestLogger(t *testing.T) { func TestLogger(t *testing.T) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
l := logger.New(grpclog.NewLoggerV2WithVerbosity(buf, buf, buf, 10)) l := logutil.NewLogger(grpclog.NewLoggerV2WithVerbosity(buf, buf, buf, 10))
l.Infof("hello world!") l.Infof("hello world!")
if !strings.Contains(buf.String(), "hello world!") { if !strings.Contains(buf.String(), "hello world!") {
t.Fatalf("expected 'hello world!', got %q", buf.String()) t.Fatalf("expected 'hello world!', got %q", buf.String())
@ -45,7 +45,7 @@ func TestLogger(t *testing.T) {
} }
buf.Reset() buf.Reset()
l = logger.New(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) l = logutil.NewLogger(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
l.Infof("ignore this") l.Infof("ignore this")
if len(buf.Bytes()) > 0 { if len(buf.Bytes()) > 0 {
t.Fatalf("unexpected logs %q", buf.String()) t.Fatalf("unexpected logs %q", buf.String())

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package logutil includes utilities to facilitate logging.
package logutil package logutil
import ( import (

View File

@ -23,16 +23,12 @@ import (
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"
) )
var (
testLogger = capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/logutil")
)
func TestMergeLogger(t *testing.T) { func TestMergeLogger(t *testing.T) {
var ( var (
txt = "hello" txt = "hello"
repeatN = 6 repeatN = 6
duration = 2049843762 * time.Nanosecond duration = 2049843762 * time.Nanosecond
mg = NewMergeLogger(testLogger) mg = NewMergeLogger(capnslog.NewPackageLogger("github.com/coreos/etcd", "pkg/logutil"))
) )
// overwrite this for testing // overwrite this for testing
defaultMergePeriod = time.Minute defaultMergePeriod = time.Minute

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package logger package logutil
import ( import (
"github.com/coreos/pkg/capnslog" "github.com/coreos/pkg/capnslog"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package logger_test package logutil_test
import ( import (
"bytes" "bytes"
@ -20,16 +20,16 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/coreos/pkg/capnslog" "github.com/coreos/etcd/pkg/logutil"
"github.com/coreos/etcd/pkg/logger" "github.com/coreos/pkg/capnslog"
) )
func TestPackageLogger(t *testing.T) { func TestPackageLogger(t *testing.T) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
capnslog.SetFormatter(capnslog.NewDefaultFormatter(buf)) capnslog.SetFormatter(capnslog.NewDefaultFormatter(buf))
l := logger.NewPackageLogger("github.com/coreos/etcd", "logger") l := logutil.NewPackageLogger("github.com/coreos/etcd", "logger")
r := capnslog.MustRepoLogger("github.com/coreos/etcd") r := capnslog.MustRepoLogger("github.com/coreos/etcd")
r.SetLogLevel(map[string]capnslog.LogLevel{"logger": capnslog.INFO}) r.SetLogLevel(map[string]capnslog.LogLevel{"logger": capnslog.INFO})