hscloud/go/mirko/trace.go
Serge Bazanski 8887655aa8 go/mirko: fix trace logging
Change-Id: I95b8ce32ad529ffe0b43282f5761495df78b2b10
2020-08-16 13:25:40 +00:00

37 lines
675 B
Go

package mirko
import (
"context"
"fmt"
"github.com/golang/glog"
"golang.org/x/net/trace"
)
func TraceInfof(ctx context.Context, f string, args ...interface{}) {
tr, ok := trace.FromContext(ctx)
if !ok {
fmtd := fmt.Sprintf(f, args...)
glog.Infof("[no trace] %v", fmtd)
return
}
tr.LazyPrintf(f, args...)
}
func TraceWarningf(ctx context.Context, f string, args ...interface{}) {
glog.Warningf(f, args...)
tr, ok := trace.FromContext(ctx)
if ok {
tr.LazyPrintf(f, args...)
}
}
func TraceErrorf(ctx context.Context, f string, args ...interface{}) {
glog.Errorf(f, args...)
tr, ok := trace.FromContext(ctx)
if ok {
tr.LazyPrintf(f, args...)
}
}