add Trace() and always log to stderr

master
q3k 2018-10-14 08:36:05 -07:00
parent b21f9b9a2e
commit aa81aa205f
1 changed files with 12 additions and 0 deletions

View File

@ -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()")