1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

Improve debugging and tracing information

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.
This commit is contained in:
Alberto Bertogli
2016-10-08 01:27:13 +01:00
parent 2b801a84d1
commit 3e6dd12d06
5 changed files with 178 additions and 71 deletions

View File

@@ -3,6 +3,7 @@ package trace
import (
"fmt"
"strconv"
"github.com/golang/glog"
nettrace "golang.org/x/net/trace"
@@ -18,16 +19,30 @@ func New(family, title string) *Trace {
return &Trace{family, title, nettrace.New(family, title)}
}
func (t *Trace) LazyPrintf(format string, a ...interface{}) {
func (t *Trace) Printf(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)
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()
}
@@ -37,8 +52,8 @@ func (t *Trace) Errorf(format string, a ...interface{}) error {
t.t.SetError()
t.t.LazyPrintf("error: %v", err)
if glog.V(2) {
msg := fmt.Sprintf("%p %s %s: error: %v", t, t.family, t.title, err)
if glog.V(0) {
msg := fmt.Sprintf("%s %s: error: %v", t.family, t.title, err)
glog.InfoDepth(1, msg)
}
return err
@@ -48,8 +63,8 @@ func (t *Trace) Error(err error) error {
t.t.SetError()
t.t.LazyPrintf("error: %v", err)
if glog.V(2) {
msg := fmt.Sprintf("%p %s %s: error: %v", t, t.family, t.title, err)
if glog.V(0) {
msg := fmt.Sprintf("%s %s: error: %v", t, t.family, t.title, err)
glog.InfoDepth(1, msg)
}
return err