1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

remove use of glog

This commit is contained in:
Asim 2016-03-14 11:01:10 +00:00
parent c0b25e7a65
commit d1eae8fabe
12 changed files with 46 additions and 85 deletions

View File

@ -110,10 +110,10 @@ $ consul agent -dev -advertise=127.0.0.1
### Run Service ### Run Service
``` ```
$ go run examples/service/main.go --logtostderr $ go run examples/service/main.go
I0102 00:22:26.413467 12018 rpc_server.go:297] Listening on [::]:62492 2016/03/14 10:59:14 Listening on [::]:50137
I0102 00:22:26.413803 12018 http_broker.go:115] Broker Listening on [::]:62493 2016/03/14 10:59:14 Broker Listening on [::]:50138
I0102 00:22:26.414009 12018 rpc_server.go:212] Registering node: greeter-e6b2fc6f-b0e6-11e5-a42f-68a86d0d36b6 2016/03/14 10:59:14 Registering node: greeter-ca62b017-e9d3-11e5-9bbb-68a86d0d36b6
``` ```
### Test Service ### Test Service
@ -216,10 +216,10 @@ func main() {
### Run service ### Run service
``` ```
go run examples/service/main.go --logtostderr go run examples/service/main.go
I0102 00:22:26.413467 12018 rpc_server.go:297] Listening on [::]:62492 2016/03/14 10:59:14 Listening on [::]:50137
I0102 00:22:26.413803 12018 http_broker.go:115] Broker Listening on [::]:62493 2016/03/14 10:59:14 Broker Listening on [::]:50138
I0102 00:22:26.414009 12018 rpc_server.go:212] Registering node: greeter-e6b2fc6f-b0e6-11e5-a42f-68a86d0d36b6 2016/03/14 10:59:14 Registering node: greeter-ca62b017-e9d3-11e5-9bbb-68a86d0d36b6
``` ```
### Define a client ### Define a client

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"
@ -17,7 +18,6 @@ import (
"sync" "sync"
"time" "time"
log "github.com/golang/glog"
"github.com/micro/go-micro/errors" "github.com/micro/go-micro/errors"
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
mls "github.com/micro/misc/lib/tls" mls "github.com/micro/misc/lib/tls"
@ -217,7 +217,7 @@ func (h *httpBroker) start() error {
return err return err
} }
log.Infof("Broker Listening on %s", l.Addr().String()) log.Printf("Broker Listening on %s", l.Addr().String())
h.address = l.Addr().String() h.address = l.Addr().String()
go http.Serve(l, h) go http.Serve(l, h)

View File

@ -1,7 +1,6 @@
package cmd package cmd
import ( import (
"flag"
"fmt" "fmt"
"io" "io"
"math/rand" "math/rand"
@ -105,36 +104,6 @@ var (
EnvVar: "MICRO_TRANSPORT_ADDRESS", EnvVar: "MICRO_TRANSPORT_ADDRESS",
Usage: "Comma-separated list of transport addresses", Usage: "Comma-separated list of transport addresses",
}, },
// logging flags
cli.BoolFlag{
Name: "logtostderr",
Usage: "log to standard error instead of files",
},
cli.BoolFlag{
Name: "alsologtostderr",
Usage: "log to standard error as well as files",
},
cli.StringFlag{
Name: "log_dir",
Usage: "log files will be written to this directory instead of the default temporary directory",
},
cli.StringFlag{
Name: "stderrthreshold",
Usage: "logs at or above this threshold go to stderr",
},
cli.StringFlag{
Name: "v",
Usage: "log level for V logs",
},
cli.StringFlag{
Name: "vmodule",
Usage: "comma-separated list of pattern=N settings for file-filtered logging",
},
cli.StringFlag{
Name: "log_backtrace_at",
Usage: "when logging hits line file:N, emit a stack trace",
},
} }
DefaultBrokers = map[string]func([]string, ...broker.Option) broker.Broker{ DefaultBrokers = map[string]func([]string, ...broker.Option) broker.Broker{
@ -218,17 +187,6 @@ func (c *cmd) Options() Options {
} }
func (c *cmd) Before(ctx *cli.Context) error { func (c *cmd) Before(ctx *cli.Context) error {
// Due to logger issues with glog, we need to do this
os.Args = os.Args[:1]
flag.Set("logtostderr", fmt.Sprintf("%v", ctx.Bool("logtostderr")))
flag.Set("alsologtostderr", fmt.Sprintf("%v", ctx.Bool("alsologtostderr")))
flag.Set("stderrthreshold", ctx.String("stderrthreshold"))
flag.Set("log_backtrace_at", ctx.String("log_backtrace_at"))
flag.Set("log_dir", ctx.String("log_dir"))
flag.Set("vmodule", ctx.String("vmodule"))
flag.Set("v", ctx.String("v"))
flag.Parse()
// If flags are set then use them otherwise do nothing // If flags are set then use them otherwise do nothing
var serverOpts []server.Option var serverOpts []server.Option
var clientOpts []client.Option var clientOpts []client.Option

View File

@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"log"
log "github.com/golang/glog"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/cmd" "github.com/micro/go-micro/cmd"
// To enable rabbitmq plugin uncomment // To enable rabbitmq plugin uncomment

View File

@ -2,9 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"log"
"time" "time"
log "github.com/golang/glog"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/cmd" "github.com/micro/go-micro/cmd"
) )
@ -24,7 +24,7 @@ func pub() {
Body: []byte(fmt.Sprintf("%d: %s", i, time.Now().String())), Body: []byte(fmt.Sprintf("%d: %s", i, time.Now().String())),
} }
if err := broker.Publish(topic, msg); err != nil { if err := broker.Publish(topic, msg); err != nil {
log.Errorf("[pub] failed: %v", err) log.Printf("[pub] failed: %v", err)
} else { } else {
fmt.Println("[pub] pubbed message:", string(msg.Body)) fmt.Println("[pub] pubbed message:", string(msg.Body))
} }

View File

@ -2,9 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"log"
"time" "time"
log "github.com/golang/glog"
"github.com/micro/go-micro/broker" "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/cmd" "github.com/micro/go-micro/cmd"
// To enable rabbitmq plugin uncomment // To enable rabbitmq plugin uncomment
@ -26,7 +26,7 @@ func pub() {
Body: []byte(fmt.Sprintf("%d: %s", i, time.Now().String())), Body: []byte(fmt.Sprintf("%d: %s", i, time.Now().String())),
} }
if err := broker.Publish(topic, msg); err != nil { if err := broker.Publish(topic, msg); err != nil {
log.Errorf("[pub] failed: %v", err) log.Printf("[pub] failed: %v", err)
} else { } else {
fmt.Println("[pub] pubbed message:", string(msg.Body)) fmt.Println("[pub] pubbed message:", string(msg.Body))
} }

View File

@ -1,7 +1,8 @@
package main package main
import ( import (
log "github.com/golang/glog" "log"
"github.com/micro/go-micro/cmd" "github.com/micro/go-micro/cmd"
"github.com/micro/go-micro/examples/server/subscriber" "github.com/micro/go-micro/examples/server/subscriber"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
@ -13,16 +14,16 @@ import (
type Example struct{} type Example struct{}
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error { func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
log.Info("Received Example.Call request") log.Print("Received Example.Call request")
rsp.Msg = server.DefaultOptions().Id + ": Hello " + req.Name rsp.Msg = server.DefaultOptions().Id + ": Hello " + req.Name
return nil return nil
} }
func (e *Example) Stream(ctx context.Context, req *example.StreamingRequest, stream example.Example_StreamStream) error { func (e *Example) Stream(ctx context.Context, req *example.StreamingRequest, stream example.Example_StreamStream) error {
log.Infof("Received Example.Stream request with count: %d", req.Count) log.Printf("Received Example.Stream request with count: %d", req.Count)
for i := 0; i < int(req.Count); i++ { for i := 0; i < int(req.Count); i++ {
log.Infof("Responding: %d", i) log.Printf("Responding: %d", i)
if err := stream.Send(&example.StreamingResponse{ if err := stream.Send(&example.StreamingResponse{
Count: int64(i), Count: int64(i),
}); err != nil { }); err != nil {
@ -39,7 +40,7 @@ func (e *Example) PingPong(ctx context.Context, stream example.Example_PingPongS
if err != nil { if err != nil {
return err return err
} }
log.Infof("Got ping %v", req.Stroke) log.Printf("Got ping %v", req.Stroke)
if err := stream.Send(&example.Pong{Stroke: req.Stroke}); err != nil { if err := stream.Send(&example.Pong{Stroke: req.Stroke}); err != nil {
return err return err
} }

View File

@ -1,7 +1,8 @@
package handler package handler
import ( import (
log "github.com/golang/glog" "log"
example "github.com/micro/go-micro/examples/server/proto/example" example "github.com/micro/go-micro/examples/server/proto/example"
"github.com/micro/go-micro/metadata" "github.com/micro/go-micro/metadata"
"github.com/micro/go-micro/server" "github.com/micro/go-micro/server"
@ -13,25 +14,25 @@ type Example struct{}
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error { func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
md, _ := metadata.FromContext(ctx) md, _ := metadata.FromContext(ctx)
log.Infof("Received Example.Call request with metadata: %v", md) log.Printf("Received Example.Call request with metadata: %v", md)
rsp.Msg = server.DefaultOptions().Id + ": Hello " + req.Name rsp.Msg = server.DefaultOptions().Id + ": Hello " + req.Name
return nil return nil
} }
func (e *Example) Stream(ctx context.Context, stream server.Streamer) error { func (e *Example) Stream(ctx context.Context, stream server.Streamer) error {
log.Info("Executing streaming handler") log.Print("Executing streaming handler")
req := &example.StreamingRequest{} req := &example.StreamingRequest{}
// We just want to receive 1 request and then process here // We just want to receive 1 request and then process here
if err := stream.Recv(req); err != nil { if err := stream.Recv(req); err != nil {
log.Errorf("Error receiving streaming request: %v", err) log.Printf("Error receiving streaming request: %v", err)
return err return err
} }
log.Infof("Received Example.Stream request with count: %d", req.Count) log.Printf("Received Example.Stream request with count: %d", req.Count)
for i := 0; i < int(req.Count); i++ { for i := 0; i < int(req.Count); i++ {
log.Infof("Responding: %d", i) log.Printf("Responding: %d", i)
if err := stream.Send(&example.StreamingResponse{ if err := stream.Send(&example.StreamingResponse{
Count: int64(i), Count: int64(i),
@ -49,7 +50,7 @@ func (e *Example) PingPong(ctx context.Context, stream server.Streamer) error {
if err := stream.Recv(req); err != nil { if err := stream.Recv(req); err != nil {
return err return err
} }
log.Infof("Got ping %v", req.Stroke) log.Printf("Got ping %v", req.Stroke)
if err := stream.Send(&example.Pong{Stroke: req.Stroke}); err != nil { if err := stream.Send(&example.Pong{Stroke: req.Stroke}); err != nil {
return err return err
} }

View File

@ -1,7 +1,8 @@
package main package main
import ( import (
log "github.com/golang/glog" "log"
"github.com/micro/go-micro/cmd" "github.com/micro/go-micro/cmd"
"github.com/micro/go-micro/examples/server/handler" "github.com/micro/go-micro/examples/server/handler"
"github.com/micro/go-micro/examples/server/subscriber" "github.com/micro/go-micro/examples/server/subscriber"

View File

@ -1,7 +1,8 @@
package subscriber package subscriber
import ( import (
log "github.com/golang/glog" "log"
example "github.com/micro/go-micro/examples/server/proto/example" example "github.com/micro/go-micro/examples/server/proto/example"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -9,11 +10,11 @@ import (
type Example struct{} type Example struct{}
func (e *Example) Handle(ctx context.Context, msg *example.Message) error { func (e *Example) Handle(ctx context.Context, msg *example.Message) error {
log.Info("Handler Received message: ", msg.Say) log.Print("Handler Received message: ", msg.Say)
return nil return nil
} }
func Handler(ctx context.Context, msg *example.Message) error { func Handler(ctx context.Context, msg *example.Message) error {
log.Info("Function Received message: ", msg.Say) log.Print("Function Received message: ", msg.Say)
return nil return nil
} }

View File

@ -2,6 +2,7 @@ package server
import ( import (
"fmt" "fmt"
"log"
"runtime/debug" "runtime/debug"
"strconv" "strconv"
"strings" "strings"
@ -13,8 +14,6 @@ import (
"github.com/micro/go-micro/registry" "github.com/micro/go-micro/registry"
"github.com/micro/go-micro/transport" "github.com/micro/go-micro/transport"
log "github.com/golang/glog"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -48,7 +47,7 @@ func newRpcServer(opts ...Option) Server {
func (s *rpcServer) accept(sock transport.Socket) { func (s *rpcServer) accept(sock transport.Socket) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Error(r, string(debug.Stack())) log.Print(r, string(debug.Stack()))
sock.Close() sock.Close()
} }
}() }()
@ -85,7 +84,7 @@ func (s *rpcServer) accept(sock transport.Socket) {
// TODO: needs better error handling // TODO: needs better error handling
if err := s.rpc.serveRequest(ctx, codec, ct); err != nil { if err := s.rpc.serveRequest(ctx, codec, ct); err != nil {
log.Errorf("Unexpected error serving request, closing socket: %v", err) log.Printf("Unexpected error serving request, closing socket: %v", err)
sock.Close() sock.Close()
} }
} }
@ -235,7 +234,7 @@ func (s *rpcServer) Register() error {
s.Unlock() s.Unlock()
if !registered { if !registered {
log.Infof("Registering node: %s", node.Id) log.Printf("Registering node: %s", node.Id)
} }
// create registry options // create registry options
@ -310,7 +309,7 @@ func (s *rpcServer) Deregister() error {
Nodes: []*registry.Node{node}, Nodes: []*registry.Node{node},
} }
log.Infof("Deregistering node: %s", node.Id) log.Printf("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
} }
@ -326,7 +325,7 @@ func (s *rpcServer) Deregister() error {
for sb, subs := range s.subscribers { for sb, subs := range s.subscribers {
for _, sub := range subs { for _, sub := range subs {
log.Infof("Unsubscribing from topic: %s", sub.Topic()) log.Printf("Unsubscribing from topic: %s", sub.Topic())
sub.Unsubscribe() sub.Unsubscribe()
} }
s.subscribers[sb] = nil s.subscribers[sb] = nil
@ -345,7 +344,7 @@ func (s *rpcServer) Start() error {
return err return err
} }
log.Infof("Listening on %s", ts.Addr()) log.Printf("Listening on %s", ts.Addr())
s.Lock() s.Lock()
s.opts.Address = ts.Addr() s.opts.Address = ts.Addr()
s.Unlock() s.Unlock()

View File

@ -29,11 +29,11 @@ and pub/sub.
package server package server
import ( import (
"log"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
log "github.com/golang/glog"
"github.com/pborman/uuid" "github.com/pborman/uuid"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -167,7 +167,7 @@ func Run() error {
ch := make(chan os.Signal, 1) ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL) signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
log.Infof("Received signal %s", <-ch) log.Printf("Received signal %s", <-ch)
if err := DefaultServer.Deregister(); err != nil { if err := DefaultServer.Deregister(); err != nil {
return err return err
@ -179,13 +179,13 @@ func Run() error {
// Starts the default server // Starts the default server
func Start() error { func Start() error {
config := DefaultServer.Options() config := DefaultServer.Options()
log.Infof("Starting server %s id %s", config.Name, config.Id) log.Printf("Starting server %s id %s", config.Name, config.Id)
return DefaultServer.Start() return DefaultServer.Start()
} }
// Stops the default server // Stops the default server
func Stop() error { func Stop() error {
log.Infof("Stopping server") log.Printf("Stopping server")
return DefaultServer.Stop() return DefaultServer.Stop()
} }