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/micro/go-micro/v2/broker"
|
||||
"github.com/micro/go-micro/v2/errors"
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
meta "github.com/micro/go-micro/v2/metadata"
|
||||
"github.com/micro/go-micro/v2/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/addr"
|
||||
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"
|
||||
|
||||
"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) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Logf(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
||||
}
|
||||
}()
|
||||
@ -656,7 +656,7 @@ func (g *grpcServer) Register() error {
|
||||
g.Unlock()
|
||||
|
||||
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
|
||||
@ -691,7 +691,7 @@ func (g *grpcServer) Register() error {
|
||||
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...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -743,7 +743,7 @@ func (g *grpcServer) Deregister() error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@ -759,7 +759,7 @@ func (g *grpcServer) Deregister() error {
|
||||
|
||||
for sb, subs := range g.subscribers {
|
||||
for _, sub := range subs {
|
||||
log.Logf("Unsubscribing from topic: %s", sub.Topic())
|
||||
log.Infof("Unsubscribing from topic: %s", sub.Topic())
|
||||
sub.Unsubscribe()
|
||||
}
|
||||
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.opts.Address = ts.Addr().String()
|
||||
g.Unlock()
|
||||
@ -811,18 +811,18 @@ func (g *grpcServer) Start() error {
|
||||
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
|
||||
if err := g.Register(); err != nil {
|
||||
log.Log("Server register error: ", err)
|
||||
log.Errorf("Server register error: ", err)
|
||||
}
|
||||
|
||||
// micro: go ts.Accept(s.accept)
|
||||
go func() {
|
||||
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
|
||||
case <-t.C:
|
||||
if err := g.Register(); err != nil {
|
||||
log.Log("Server register error: ", err)
|
||||
log.Error("Server register error: ", err)
|
||||
}
|
||||
// wait for exit
|
||||
case ch = <-g.exit:
|
||||
@ -854,7 +854,7 @@ func (g *grpcServer) Start() error {
|
||||
|
||||
// deregister self
|
||||
if err := g.Deregister(); err != nil {
|
||||
log.Log("Server deregister error: ", err)
|
||||
log.Error("Server deregister error: ", err)
|
||||
}
|
||||
|
||||
// wait for waitgroup
|
||||
@ -879,7 +879,7 @@ func (g *grpcServer) Start() error {
|
||||
// close transport
|
||||
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
|
||||
config.Broker.Disconnect()
|
||||
}()
|
||||
|
20
server.go
20
server.go
@ -14,8 +14,8 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
log "github.com/micro/go-micro/v2/logger"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -86,7 +86,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
||||
replyType = mtype.In(3)
|
||||
contextType = mtype.In(1)
|
||||
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
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
||||
// check stream type
|
||||
streamType := reflect.TypeOf((*server.Stream)(nil)).Elem()
|
||||
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
|
||||
}
|
||||
} else {
|
||||
@ -102,30 +102,30 @@ func prepareEndpoint(method reflect.Method) *methodType {
|
||||
|
||||
// First arg need not be a pointer.
|
||||
if !isExportedOrBuiltinType(argType) {
|
||||
log.Log(mname, "argument type not exported:", argType)
|
||||
log.Error(mname, "argument type not exported:", argType)
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Reply type must be exported.
|
||||
if !isExportedOrBuiltinType(replyType) {
|
||||
log.Log("method", mname, "reply type not exported:", replyType)
|
||||
log.Error("method", mname, "reply type not exported:", replyType)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Endpoint() needs one out.
|
||||
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
|
||||
}
|
||||
// The return type of the method must be error.
|
||||
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 &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) {
|
||||
s := "rpc Register: type " + sname + " is not exported"
|
||||
log.Log(s)
|
||||
log.Error(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
if _, present := server.serviceMap[sname]; present {
|
||||
@ -165,7 +165,7 @@ func (server *rServer) register(rcvr interface{}) error {
|
||||
|
||||
if len(s.method) == 0 {
|
||||
s := "rpc Register: type " + sname + " has no exported methods of suitable type"
|
||||
log.Log(s)
|
||||
log.Error(s)
|
||||
return errors.New(s)
|
||||
}
|
||||
server.serviceMap[s.name] = s
|
||||
|
@ -9,10 +9,10 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/v2/broker"
|
||||
"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/registry"
|
||||
"github.com/micro/go-micro/v2/server"
|
||||
"github.com/micro/go-micro/v2/util/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -171,8 +171,8 @@ func (g *grpcServer) createSubHandler(sb *subscriber, opts server.Options) broke
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Log("panic recovered: ", r)
|
||||
log.Logf(string(debug.Stack()))
|
||||
log.Error("panic recovered: ", r)
|
||||
log.Error(string(debug.Stack()))
|
||||
err = errors.InternalServerError("go.micro.server", "panic recovered: %v", r)
|
||||
}
|
||||
}()
|
||||
|
Loading…
x
Reference in New Issue
Block a user