mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-12-25 02:10:46 +00:00
logger: add FromLogrus
service: use logger instead of logrus Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
d8443ee470
commit
bb7e4b124b
@ -21,6 +21,10 @@ func New() Logger {
|
||||
return &logger{fl: logrus.New()}
|
||||
}
|
||||
|
||||
func FromLogrus(fl logrus.FieldLogger) Logger {
|
||||
return &logger{fl: fl}
|
||||
}
|
||||
|
||||
type Logger interface {
|
||||
WithField(key string, value interface{}) Logger
|
||||
WithFields(kv ...interface{}) Logger
|
||||
|
@ -194,7 +194,7 @@ func (s *Server) recv(c *net.UDPConn) {
|
||||
continue
|
||||
}
|
||||
if err := s.parsePacket(buf[:n], from); err != nil {
|
||||
logrus.Errorf("[ERR] mdns: Failed to handle query: %v", err)
|
||||
logrus.Errorf("mdns: Failed to handle query: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,7 +203,7 @@ func (s *Server) recv(c *net.UDPConn) {
|
||||
func (s *Server) parsePacket(packet []byte, from net.Addr) error {
|
||||
var msg dns.Msg
|
||||
if err := msg.Unpack(packet); err != nil {
|
||||
logrus.Errorf("[ERR] mdns: Failed to unpack packet: %v", err)
|
||||
logrus.Errorf("mdns: Failed to unpack packet: %v", err)
|
||||
return err
|
||||
}
|
||||
// TODO: This is a bit of a hack
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/justinas/alice"
|
||||
"github.com/rs/cors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/soheilhy/cmux"
|
||||
"go.uber.org/multierr"
|
||||
"google.golang.org/grpc"
|
||||
@ -29,6 +28,7 @@ import (
|
||||
greflect "google.golang.org/grpc/reflection"
|
||||
|
||||
"go.linka.cloud/grpc/interceptors/metadata"
|
||||
"go.linka.cloud/grpc/logger"
|
||||
"go.linka.cloud/grpc/registry"
|
||||
"go.linka.cloud/grpc/registry/noop"
|
||||
)
|
||||
@ -240,11 +240,11 @@ func (s *service) run() error {
|
||||
select {
|
||||
case sig := <-sigs:
|
||||
fmt.Println()
|
||||
logrus.Warnf("received %v", sig)
|
||||
logger.C(s.opts.ctx).Warnf("received %v", sig)
|
||||
return s.Close()
|
||||
case err := <-errs:
|
||||
if err != nil && !ignoreMuxError(err) {
|
||||
logrus.Error(err)
|
||||
logger.C(s.opts.ctx).Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -256,6 +256,7 @@ func (s *service) Start() error {
|
||||
}
|
||||
|
||||
func (s *service) Stop() error {
|
||||
log := logger.C(s.opts.ctx)
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if !s.running {
|
||||
@ -267,7 +268,7 @@ func (s *service) Stop() error {
|
||||
}
|
||||
}
|
||||
if err := s.opts.registry.Deregister(s.regSvc); err != nil {
|
||||
logrus.Errorf("failed to deregister service: %v", err)
|
||||
log.Errorf("failed to deregister service: %v", err)
|
||||
}
|
||||
defer close(s.closed)
|
||||
sigs := s.notify()
|
||||
@ -279,14 +280,14 @@ func (s *service) Stop() error {
|
||||
// catch: Drain() is not implemented
|
||||
recover()
|
||||
}()
|
||||
logrus.Warn("shutting down gracefully")
|
||||
log.Warn("shutting down gracefully")
|
||||
s.server.GracefulStop()
|
||||
}()
|
||||
select {
|
||||
case sig := <-sigs:
|
||||
fmt.Println()
|
||||
logrus.Warnf("received %v", sig)
|
||||
logrus.Warn("forcing shutdown")
|
||||
log.Warnf("received %v", sig)
|
||||
log.Warn("forcing shutdown")
|
||||
s.server.Stop()
|
||||
case <-done:
|
||||
}
|
||||
@ -297,7 +298,7 @@ func (s *service) Stop() error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
logrus.Info("server stopped")
|
||||
log.Info("server stopped")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -322,7 +323,7 @@ func (s *service) registerService(sd *grpc.ServiceDesc, ss interface{}) {
|
||||
s.inproc.RegisterService(sd, ss)
|
||||
|
||||
if _, ok := s.services[sd.ServiceName]; ok {
|
||||
logrus.Fatalf("grpc: Service.RegisterService found duplicate service registration for %q", sd.ServiceName)
|
||||
logger.C(s.opts.ctx).Fatalf("grpc: Service.RegisterService found duplicate service registration for %q", sd.ServiceName)
|
||||
}
|
||||
info := &serviceInfo{
|
||||
serviceImpl: ss,
|
||||
|
Loading…
Reference in New Issue
Block a user