Sergiusz Bazanski | 1fad2e5 | 2019-08-01 20:16:27 +0200 | [diff] [blame] | 1 | package mirko |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | |
| 7 | "github.com/golang/glog" |
| 8 | "golang.org/x/net/trace" |
| 9 | ) |
| 10 | |
| 11 | func TraceInfof(ctx context.Context, f string, args ...interface{}) { |
| 12 | tr, ok := trace.FromContext(ctx) |
| 13 | if !ok { |
| 14 | fmtd := fmt.Sprintf(f, args...) |
Serge Bazanski | 8887655 | 2020-08-16 15:24:58 +0200 | [diff] [blame] | 15 | glog.Infof("[no trace] %v", fmtd) |
Sergiusz Bazanski | 1fad2e5 | 2019-08-01 20:16:27 +0200 | [diff] [blame] | 16 | return |
| 17 | } |
| 18 | tr.LazyPrintf(f, args...) |
| 19 | } |
| 20 | |
| 21 | func TraceWarningf(ctx context.Context, f string, args ...interface{}) { |
| 22 | glog.Warningf(f, args...) |
| 23 | |
| 24 | tr, ok := trace.FromContext(ctx) |
| 25 | if ok { |
| 26 | tr.LazyPrintf(f, args...) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func TraceErrorf(ctx context.Context, f string, args ...interface{}) { |
| 31 | glog.Errorf(f, args...) |
| 32 | |
| 33 | tr, ok := trace.FromContext(ctx) |
| 34 | if ok { |
| 35 | tr.LazyPrintf(f, args...) |
| 36 | } |
| 37 | } |