mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
This patch reviews various debug and informational messages, making more uniform use of tracing, and extends the monitoring http server with useful information like an index and a queue dump.
76 lines
1.4 KiB
Go
76 lines
1.4 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 {
|
|
return &Trace{family, title, nettrace.New(family, title)}
|
|
}
|
|
|
|
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(2, msg)
|
|
}
|
|
}
|
|
|
|
func (t *Trace) Debugf(format string, a ...interface{}) {
|
|
if glog.V(2) {
|
|
t.t.LazyPrintf(format, a...)
|
|
msg := fmt.Sprintf("%s %s: %s", t.family, t.title,
|
|
quote(fmt.Sprintf(format, a...)))
|
|
glog.InfoDepth(2, 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()
|
|
}
|