From aa81aa205ff6b570606c2f71542d35d426eabb7d Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Sun, 14 Oct 2018 08:36:05 -0700 Subject: [PATCH] add Trace() and always log to stderr --- mirko.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mirko.go b/mirko.go index 3acf9b1e..a2ed85d5 100644 --- a/mirko.go +++ b/mirko.go @@ -1,6 +1,7 @@ package mirko import ( + "context" "flag" "fmt" "net" @@ -23,6 +24,7 @@ var ( func init() { flag.StringVar(&flagListenAddress, "listen_address", "127.0.0.1:42000", "gRPC listen address") flag.StringVar(&flagDebugAddress, "debug_address", "127.0.0.1:42001", "HTTP debug/status listen address") + flag.Set("logtostderr", "true") } type Mirko struct { @@ -82,6 +84,16 @@ func (m *Mirko) Listen() error { return nil } +func (m *Mirko) Trace(ctx context.Context, f string, args ...interface{}) { + tr, ok := trace.FromContext(ctx) + if !ok { + fmtd := fmt.Sprintf(f, args...) + glog.Warningf("No trace in %v: %s", ctx, fmtd) + return + } + tr.LazyPrintf(f, args...) +} + func (m *Mirko) GRPC() *grpc.Server { if m.grpcServer == nil { panic("GRPC() called before Listen()")