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