author | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-10-09 17:58:48 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-10-09 23:51:05 UTC |
parent | 112e492c3a68f511644ecc16baf6d207f048c055 |
internal/trace/trace.go | +41 | -0 |
diff --git a/internal/trace/trace.go b/internal/trace/trace.go index bcddf04..6f705b2 100644 --- a/internal/trace/trace.go +++ b/internal/trace/trace.go @@ -80,3 +80,44 @@ func (t *Trace) Error(err error) error { func (t *Trace) Finish() { t.t.Finish() } + +type EventLog struct { + family string + title string + e nettrace.EventLog +} + +func NewEventLog(family, title string) *EventLog { + return &EventLog{family, title, nettrace.NewEventLog(family, title)} +} + +func (e *EventLog) Printf(format string, a ...interface{}) { + e.e.Printf(format, a...) + + if glog.V(0) { + msg := fmt.Sprintf("%s %s: %s", e.family, e.title, + quote(fmt.Sprintf(format, a...))) + glog.InfoDepth(1, msg) + } +} + +func (e *EventLog) Debugf(format string, a ...interface{}) { + e.e.Printf(format, a...) + + if glog.V(2) { + msg := fmt.Sprintf("%s %s: %s", e.family, e.title, + quote(fmt.Sprintf(format, a...))) + glog.InfoDepth(1, msg) + } +} + +func (e *EventLog) Errorf(format string, a ...interface{}) error { + err := fmt.Errorf(format, a...) + e.e.Errorf("error: %v", err) + + if glog.V(0) { + msg := fmt.Sprintf("%s %s: error: %v", e.family, e.title, err) + glog.InfoDepth(1, msg) + } + return err +}