author | Alberto Bertogli
<albertito@blitiri.com.ar> 2015-11-06 03:45:36 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2015-11-06 10:27:11 UTC |
parent | 58de5a62005347be4012fcbc6c6131c4864526e2 |
chasquid.go | +3 | -3 |
internal/queue/queue.go | +0 | -1 |
internal/trace/trace.go | +44 | -0 |
diff --git a/chasquid.go b/chasquid.go index 98dade2..e7a7273 100644 --- a/chasquid.go +++ b/chasquid.go @@ -19,11 +19,11 @@ import ( "blitiri.com.ar/go/chasquid/internal/config" "blitiri.com.ar/go/chasquid/internal/queue" "blitiri.com.ar/go/chasquid/internal/systemd" + "blitiri.com.ar/go/chasquid/internal/trace" _ "net/http/pprof" "github.com/golang/glog" - "golang.org/x/net/trace" ) var ( @@ -443,7 +443,7 @@ func (c *Conn) RCPT(params string) (code int, msg string) { return 250, "You have an eerie feeling..." } -func (c *Conn) DATA(params string, tr trace.Trace) (code int, msg string) { +func (c *Conn) DATA(params string, tr *trace.Trace) (code int, msg string) { if c.mail_from == "" { return 503, "sender not yet given" } @@ -500,7 +500,7 @@ func (c *Conn) DATA(params string, tr trace.Trace) (code int, msg string) { return 250, msgs[rand.Int()%len(msgs)] } -func (c *Conn) STARTTLS(params string, tr trace.Trace) (code int, msg string) { +func (c *Conn) STARTTLS(params string, tr *trace.Trace) (code int, msg string) { if c.onTLS { return 503, "You are already wearing that!" } diff --git a/internal/queue/queue.go b/internal/queue/queue.go index 538077b..e46d251 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -142,7 +142,6 @@ func (item *Item) SendLoop(q *Queue) { } tr.LazyPrintf("%s sending", to) - glog.Infof("%s %q -> %q", item.ID, item.From, to) // TODO: deliver, serially or in parallel with a waitgroup. // Fake a successful send for now. diff --git a/internal/trace/trace.go b/internal/trace/trace.go new file mode 100644 index 0000000..f2b5952 --- /dev/null +++ b/internal/trace/trace.go @@ -0,0 +1,44 @@ +// Package trace extends golang.org/x/net/trace. +package trace + +import ( + "fmt" + + "github.com/golang/glog" + nettrace "golang.org/x/net/trace" +) + +type Trace struct { + family string + title string + t nettrace.Trace +} + +func New(family, title string) *Trace { + return &Trace{family, title, nettrace.New(family, title)} +} + +func (t *Trace) LazyPrintf(format string, a ...interface{}) { + t.t.LazyPrintf(format, a...) + + if glog.V(2) { + msg := fmt.Sprintf("%p %s %s: %+q", t, t.family, t.title, + fmt.Sprintf(format, a...)) + glog.InfoDepth(1, msg) + } +} + +func (t *Trace) SetError() { + t.t.SetError() +} + +func (t *Trace) Errorf(format string, a ...interface{}) error { + err := fmt.Errorf(format, a...) + t.t.SetError() + t.LazyPrintf("Error: %v", err) + return err +} + +func (t *Trace) Finish() { + t.t.Finish() +}