mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
The default for max events is 10, which is a bit short for a normal SMTP exchange. Expand it to 30 which should be large enough to keep most of the traces.
83 lines
1.6 KiB
Go
83 lines
1.6 KiB
Go
// Package trace extends golang.org/x/net/trace.
|
|
package trace
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"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 {
|
|
t := &Trace{family, title, nettrace.New(family, title)}
|
|
|
|
// The default for max events is 10, which is a bit short for a normal
|
|
// SMTP exchange. Expand it to 30 which should be large enough to keep
|
|
// most of the traces.
|
|
t.t.SetMaxEvents(30)
|
|
return t
|
|
}
|
|
|
|
func (t *Trace) Printf(format string, a ...interface{}) {
|
|
t.t.LazyPrintf(format, a...)
|
|
|
|
if glog.V(0) {
|
|
msg := fmt.Sprintf("%s %s: %s", t.family, t.title,
|
|
quote(fmt.Sprintf(format, a...)))
|
|
glog.InfoDepth(1, msg)
|
|
}
|
|
}
|
|
|
|
func (t *Trace) Debugf(format string, a ...interface{}) {
|
|
t.t.LazyPrintf(format, a...)
|
|
|
|
if glog.V(2) {
|
|
msg := fmt.Sprintf("%s %s: %s", t.family, t.title,
|
|
quote(fmt.Sprintf(format, a...)))
|
|
glog.InfoDepth(1, msg)
|
|
}
|
|
}
|
|
|
|
func quote(s string) string {
|
|
qs := strconv.Quote(s)
|
|
return qs[1 : len(qs)-1]
|
|
}
|
|
|
|
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.t.LazyPrintf("error: %v", err)
|
|
|
|
if glog.V(0) {
|
|
msg := fmt.Sprintf("%s %s: error: %v", t.family, t.title, err)
|
|
glog.InfoDepth(1, msg)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (t *Trace) Error(err error) error {
|
|
t.t.SetError()
|
|
t.t.LazyPrintf("error: %v", err)
|
|
|
|
if glog.V(0) {
|
|
msg := fmt.Sprintf("%s %s: error: %v", t, t.family, t.title, err)
|
|
glog.InfoDepth(1, msg)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (t *Trace) Finish() {
|
|
t.t.Finish()
|
|
}
|