From cf36003e3af73b18ec3d1abf4820fff5caa61b52 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sun, 9 Oct 2016 18:58:48 +0100 Subject: [PATCH] trace: Add an EventLog This patch adds an EventLog wrapper to the trace module, which will be used in the future to track long-lived objects. --- internal/trace/trace.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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 +}