Commit 52bbe55a authored by Janos Guljas's avatar Janos Guljas

unify Logger interface

parent d2691baa
...@@ -49,7 +49,7 @@ func (c *command) initStartCmd() (err error) { ...@@ -49,7 +49,7 @@ func (c *command) initStartCmd() (err error) {
return cmd.Help() return cmd.Help()
} }
logger := logging.New(cmd.OutOrStdout()) logger := logging.New(cmd.OutOrStdout()).(*logrus.Logger)
switch v := strings.ToLower(c.config.GetString(optionNameVerbosity)); v { switch v := strings.ToLower(c.config.GetString(optionNameVerbosity)); v {
case "0", "silent": case "0", "silent":
logger.SetOutput(ioutil.Discard) logger.SetOutput(ioutil.Discard)
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/pingpong" "github.com/ethersphere/bee/pkg/pingpong"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"resenje.org/web" "resenje.org/web"
...@@ -26,10 +27,7 @@ type server struct { ...@@ -26,10 +27,7 @@ type server struct {
type Options struct { type Options struct {
Pingpong pingpong.Interface Pingpong pingpong.Interface
Logger interface { Logger logging.Logger
Debugf(format string, args ...interface{})
Errorf(format string, args ...interface{})
}
} }
func New(o Options) Service { func New(o Options) Service {
......
...@@ -10,11 +10,25 @@ import ( ...@@ -10,11 +10,25 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
func New(w io.Writer) *logrus.Logger { type Logger interface {
logger := logrus.New() Tracef(format string, args ...interface{})
logger.SetOutput(w) Trace(args ...interface{})
logger.Formatter = &logrus.TextFormatter{ Debugf(format string, args ...interface{})
Debug(args ...interface{})
Infof(format string, args ...interface{})
Info(args ...interface{})
Warningf(format string, args ...interface{})
Warning(args ...interface{})
Errorf(format string, args ...interface{})
Error(args ...interface{})
SetOutput(io.Writer)
}
func New(w io.Writer) Logger {
l := logrus.New()
l.SetOutput(w)
l.Formatter = &logrus.TextFormatter{
FullTimestamp: true, FullTimestamp: true,
} }
return logger return l
} }
...@@ -7,6 +7,7 @@ package handshake ...@@ -7,6 +7,7 @@ package handshake
import ( import (
"fmt" "fmt"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/pb" "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake/pb"
"github.com/ethersphere/bee/pkg/p2p/protobuf" "github.com/ethersphere/bee/pkg/p2p/protobuf"
...@@ -21,10 +22,10 @@ const ( ...@@ -21,10 +22,10 @@ const (
type Service struct { type Service struct {
overlay string overlay string
networkID int32 networkID int32
logger Logger logger logging.Logger
} }
func New(overlay string, networkID int32, logger Logger) *Service { func New(overlay string, networkID int32, logger logging.Logger) *Service {
return &Service{ return &Service{
overlay: overlay, overlay: overlay,
networkID: networkID, networkID: networkID,
...@@ -32,10 +33,6 @@ func New(overlay string, networkID int32, logger Logger) *Service { ...@@ -32,10 +33,6 @@ func New(overlay string, networkID int32, logger Logger) *Service {
} }
} }
type Logger interface {
Tracef(format string, args ...interface{})
}
func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) { func (s *Service) Handshake(stream p2p.Stream) (i *Info, err error) {
w, r := protobuf.NewWriterAndReader(stream) w, r := protobuf.NewWriterAndReader(stream)
var resp pb.ShakeHand var resp pb.ShakeHand
......
...@@ -17,8 +17,8 @@ import ( ...@@ -17,8 +17,8 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
handshake "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake" handshake "github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake"
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
autonat "github.com/libp2p/go-libp2p-autonat-svc" autonat "github.com/libp2p/go-libp2p-autonat-svc"
...@@ -49,7 +49,7 @@ type Service struct { ...@@ -49,7 +49,7 @@ type Service struct {
networkID int32 networkID int32
handshakeService *handshake.Service handshakeService *handshake.Service
peers *peerRegistry peers *peerRegistry
logger Logger logger logging.Logger
} }
type Options struct { type Options struct {
...@@ -62,13 +62,7 @@ type Options struct { ...@@ -62,13 +62,7 @@ type Options struct {
ConnectionsLow int ConnectionsLow int
ConnectionsHigh int ConnectionsHigh int
ConnectionsGrace time.Duration ConnectionsGrace time.Duration
Logger Logger Logger logging.Logger
}
type Logger interface {
Tracef(format string, args ...interface{})
Infof(format string, args ...interface{})
Errorf(format string, args ...interface{})
} }
func New(ctx context.Context, o Options) (*Service, error) { func New(ctx context.Context, o Options) (*Service, error) {
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"io" "io"
"time" "time"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p" "github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/protobuf" "github.com/ethersphere/bee/pkg/p2p/protobuf"
"github.com/ethersphere/bee/pkg/pingpong/pb" "github.com/ethersphere/bee/pkg/pingpong/pb"
...@@ -27,17 +28,13 @@ type Interface interface { ...@@ -27,17 +28,13 @@ type Interface interface {
type Service struct { type Service struct {
streamer p2p.Streamer streamer p2p.Streamer
logger Logger logger logging.Logger
metrics metrics metrics metrics
} }
type Options struct { type Options struct {
Streamer p2p.Streamer Streamer p2p.Streamer
Logger Logger Logger logging.Logger
}
type Logger interface {
Debugf(format string, args ...interface{})
} }
func New(o Options) *Service { func New(o Options) *Service {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment