prune util/log and user logger (#1237)
* prune util/log and user logger Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * plaintext logger Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * add newline Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
cf4b4aecda
commit
28ef20ef4a
28
grpc.go
28
grpc.go
@ -17,12 +17,12 @@ import (
|
|||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/micro/go-micro/v2/broker"
|
"github.com/micro/go-micro/v2/broker"
|
||||||
"github.com/micro/go-micro/v2/errors"
|
"github.com/micro/go-micro/v2/errors"
|
||||||
|
log "github.com/micro/go-micro/v2/logger"
|
||||||
meta "github.com/micro/go-micro/v2/metadata"
|
meta "github.com/micro/go-micro/v2/metadata"
|
||||||
"github.com/micro/go-micro/v2/registry"
|
"github.com/micro/go-micro/v2/registry"
|
||||||
"github.com/micro/go-micro/v2/server"
|
"github.com/micro/go-micro/v2/server"
|
||||||
"github.com/micro/go-micro/v2/util/addr"
|
"github.com/micro/go-micro/v2/util/addr"
|
||||||
mgrpc "github.com/micro/go-micro/v2/util/grpc"
|
mgrpc "github.com/micro/go-micro/v2/util/grpc"
|
||||||
"github.com/micro/go-micro/v2/util/log"
|
|
||||||
mnet "github.com/micro/go-micro/v2/util/net"
|
mnet "github.com/micro/go-micro/v2/util/net"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@ -356,8 +356,8 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service,
|
|||||||
fn := func(ctx context.Context, req server.Request, rsp interface{}) (err error) {
|
fn := func(ctx context.Context, req server.Request, rsp interface{}) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Log("panic recovered: ", r)
|
log.Error("panic recovered: ", r)
|
||||||
log.Logf(string(debug.Stack()))
|
log.Error(string(debug.Stack()))
|
||||||
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -656,7 +656,7 @@ func (g *grpcServer) Register() error {
|
|||||||
g.Unlock()
|
g.Unlock()
|
||||||
|
|
||||||
if !registered {
|
if !registered {
|
||||||
log.Logf("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
|
log.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create registry options
|
// create registry options
|
||||||
@ -691,7 +691,7 @@ func (g *grpcServer) Register() error {
|
|||||||
opts = append(opts, broker.DisableAutoAck())
|
opts = append(opts, broker.DisableAutoAck())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Logf("Subscribing to topic: %s", sb.Topic())
|
log.Infof("Subscribing to topic: %s", sb.Topic())
|
||||||
sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...)
|
sub, err := config.Broker.Subscribe(sb.Topic(), handler, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -743,7 +743,7 @@ func (g *grpcServer) Deregister() error {
|
|||||||
Nodes: []*registry.Node{node},
|
Nodes: []*registry.Node{node},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Logf("Deregistering node: %s", node.Id)
|
log.Infof("Deregistering node: %s", node.Id)
|
||||||
if err := config.Registry.Deregister(service); err != nil {
|
if err := config.Registry.Deregister(service); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -759,7 +759,7 @@ func (g *grpcServer) Deregister() error {
|
|||||||
|
|
||||||
for sb, subs := range g.subscribers {
|
for sb, subs := range g.subscribers {
|
||||||
for _, sub := range subs {
|
for _, sub := range subs {
|
||||||
log.Logf("Unsubscribing from topic: %s", sub.Topic())
|
log.Infof("Unsubscribing from topic: %s", sub.Topic())
|
||||||
sub.Unsubscribe()
|
sub.Unsubscribe()
|
||||||
}
|
}
|
||||||
g.subscribers[sb] = nil
|
g.subscribers[sb] = nil
|
||||||
@ -799,7 +799,7 @@ func (g *grpcServer) Start() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Logf("Server [grpc] Listening on %s", ts.Addr().String())
|
log.Infof("Server [grpc] Listening on %s", ts.Addr().String())
|
||||||
g.Lock()
|
g.Lock()
|
||||||
g.opts.Address = ts.Addr().String()
|
g.opts.Address = ts.Addr().String()
|
||||||
g.Unlock()
|
g.Unlock()
|
||||||
@ -811,18 +811,18 @@ func (g *grpcServer) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Logf("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address())
|
log.Infof("Broker [%s] Connected to %s", config.Broker.String(), config.Broker.Address())
|
||||||
}
|
}
|
||||||
|
|
||||||
// announce self to the world
|
// announce self to the world
|
||||||
if err := g.Register(); err != nil {
|
if err := g.Register(); err != nil {
|
||||||
log.Log("Server register error: ", err)
|
log.Errorf("Server register error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// micro: go ts.Accept(s.accept)
|
// micro: go ts.Accept(s.accept)
|
||||||
go func() {
|
go func() {
|
||||||
if err := g.srv.Serve(ts); err != nil {
|
if err := g.srv.Serve(ts); err != nil {
|
||||||
log.Log("gRPC Server start error: ", err)
|
log.Errorf("gRPC Server start error: ", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -844,7 +844,7 @@ func (g *grpcServer) Start() error {
|
|||||||
// register self on interval
|
// register self on interval
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
if err := g.Register(); err != nil {
|
if err := g.Register(); err != nil {
|
||||||
log.Log("Server register error: ", err)
|
log.Error("Server register error: ", err)
|
||||||
}
|
}
|
||||||
// wait for exit
|
// wait for exit
|
||||||
case ch = <-g.exit:
|
case ch = <-g.exit:
|
||||||
@ -854,7 +854,7 @@ func (g *grpcServer) Start() error {
|
|||||||
|
|
||||||
// deregister self
|
// deregister self
|
||||||
if err := g.Deregister(); err != nil {
|
if err := g.Deregister(); err != nil {
|
||||||
log.Log("Server deregister error: ", err)
|
log.Error("Server deregister error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for waitgroup
|
// wait for waitgroup
|
||||||
@ -879,7 +879,7 @@ func (g *grpcServer) Start() error {
|
|||||||
// close transport
|
// close transport
|
||||||
ch <- nil
|
ch <- nil
|
||||||
|
|
||||||
log.Logf("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address())
|
log.Infof("Broker [%s] Disconnected from %s", config.Broker.String(), config.Broker.Address())
|
||||||
// disconnect broker
|
// disconnect broker
|
||||||
config.Broker.Disconnect()
|
config.Broker.Disconnect()
|
||||||
}()
|
}()
|
||||||
|
20
server.go
20
server.go
@ -14,8 +14,8 @@ import (
|
|||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
log "github.com/micro/go-micro/v2/logger"
|
||||||
"github.com/micro/go-micro/v2/server"
|
"github.com/micro/go-micro/v2/server"
|
||||||
"github.com/micro/go-micro/v2/util/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -86,7 +86,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
|||||||
replyType = mtype.In(3)
|
replyType = mtype.In(3)
|
||||||
contextType = mtype.In(1)
|
contextType = mtype.In(1)
|
||||||
default:
|
default:
|
||||||
log.Log("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn())
|
log.Error("method", mname, "of", mtype, "has wrong number of ins:", mtype.NumIn())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
|||||||
// check stream type
|
// check stream type
|
||||||
streamType := reflect.TypeOf((*server.Stream)(nil)).Elem()
|
streamType := reflect.TypeOf((*server.Stream)(nil)).Elem()
|
||||||
if !argType.Implements(streamType) {
|
if !argType.Implements(streamType) {
|
||||||
log.Log(mname, "argument does not implement Streamer interface:", argType)
|
log.Error(mname, "argument does not implement Streamer interface:", argType)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -102,30 +102,30 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
|||||||
|
|
||||||
// First arg need not be a pointer.
|
// First arg need not be a pointer.
|
||||||
if !isExportedOrBuiltinType(argType) {
|
if !isExportedOrBuiltinType(argType) {
|
||||||
log.Log(mname, "argument type not exported:", argType)
|
log.Error(mname, "argument type not exported:", argType)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if replyType.Kind() != reflect.Ptr {
|
if replyType.Kind() != reflect.Ptr {
|
||||||
log.Log("method", mname, "reply type not a pointer:", replyType)
|
log.Error("method", mname, "reply type not a pointer:", replyType)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reply type must be exported.
|
// Reply type must be exported.
|
||||||
if !isExportedOrBuiltinType(replyType) {
|
if !isExportedOrBuiltinType(replyType) {
|
||||||
log.Log("method", mname, "reply type not exported:", replyType)
|
log.Error("method", mname, "reply type not exported:", replyType)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Endpoint() needs one out.
|
// Endpoint() needs one out.
|
||||||
if mtype.NumOut() != 1 {
|
if mtype.NumOut() != 1 {
|
||||||
log.Log("method", mname, "has wrong number of outs:", mtype.NumOut())
|
log.Error("method", mname, "has wrong number of outs:", mtype.NumOut())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// The return type of the method must be error.
|
// The return type of the method must be error.
|
||||||
if returnType := mtype.Out(0); returnType != typeOfError {
|
if returnType := mtype.Out(0); returnType != typeOfError {
|
||||||
log.Log("method", mname, "returns", returnType.String(), "not error")
|
log.Error("method", mname, "returns", returnType.String(), "not error")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &methodType{method: method, ArgType: argType, ReplyType: replyType, ContextType: contextType, stream: stream}
|
return &methodType{method: method, ArgType: argType, ReplyType: replyType, ContextType: contextType, stream: stream}
|
||||||
@ -146,7 +146,7 @@ func (server *rServer) register(rcvr interface{}) error {
|
|||||||
}
|
}
|
||||||
if !isExported(sname) {
|
if !isExported(sname) {
|
||||||
s := "rpc Register: type " + sname + " is not exported"
|
s := "rpc Register: type " + sname + " is not exported"
|
||||||
log.Log(s)
|
log.Error(s)
|
||||||
return errors.New(s)
|
return errors.New(s)
|
||||||
}
|
}
|
||||||
if _, present := server.serviceMap[sname]; present {
|
if _, present := server.serviceMap[sname]; present {
|
||||||
@ -165,7 +165,7 @@ func (server *rServer) register(rcvr interface{}) error {
|
|||||||
|
|
||||||
if len(s.method) == 0 {
|
if len(s.method) == 0 {
|
||||||
s := "rpc Register: type " + sname + " has no exported methods of suitable type"
|
s := "rpc Register: type " + sname + " has no exported methods of suitable type"
|
||||||
log.Log(s)
|
log.Error(s)
|
||||||
return errors.New(s)
|
return errors.New(s)
|
||||||
}
|
}
|
||||||
server.serviceMap[s.name] = s
|
server.serviceMap[s.name] = s
|
||||||
|
@ -9,10 +9,10 @@ import (
|
|||||||
|
|
||||||
"github.com/micro/go-micro/v2/broker"
|
"github.com/micro/go-micro/v2/broker"
|
||||||
"github.com/micro/go-micro/v2/errors"
|
"github.com/micro/go-micro/v2/errors"
|
||||||
|
log "github.com/micro/go-micro/v2/logger"
|
||||||
"github.com/micro/go-micro/v2/metadata"
|
"github.com/micro/go-micro/v2/metadata"
|
||||||
"github.com/micro/go-micro/v2/registry"
|
"github.com/micro/go-micro/v2/registry"
|
||||||
"github.com/micro/go-micro/v2/server"
|
"github.com/micro/go-micro/v2/server"
|
||||||
"github.com/micro/go-micro/v2/util/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -171,8 +171,8 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Log("panic recovered: ", r)
|
log.Error("panic recovered: ", r)
|
||||||
log.Logf(string(debug.Stack()))
|
log.Error(string(debug.Stack()))
|
||||||
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user