mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
Introduce a trace wrapper
This patch introduces a wrapper to golang.org/x/net/trace with a new method that will be useful later on, making logging and tracing less verbose.
This commit is contained in:
@@ -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!"
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
44
internal/trace/trace.go
Normal file
44
internal/trace/trace.go
Normal file
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user