diff --git a/go/vt/logutil/console_logger.go b/go/vt/logutil/console_logger.go index fe43985a8b6..b5a34244c28 100644 --- a/go/vt/logutil/console_logger.go +++ b/go/vt/logutil/console_logger.go @@ -6,9 +6,7 @@ import ( log "github.com/golang/glog" ) -// ConsoleLogger is a Logger that uses glog directly to log. -// We can't specify the depth of the stack trace, -// So we just find it and add it to the message. +// ConsoleLogger is a Logger that uses glog directly to log, at the right level. type ConsoleLogger struct{} // NewConsoleLogger returns a simple ConsoleLogger @@ -18,26 +16,17 @@ func NewConsoleLogger() ConsoleLogger { // Infof is part of the Logger interface func (cl ConsoleLogger) Infof(format string, v ...interface{}) { - file, line := fileAndLine(3) - vals := []interface{}{file, line} - vals = append(vals, v...) - log.Infof("%v:%v] "+format, vals...) + log.InfoDepth(2, fmt.Sprintf(format, v...)) } // Warningf is part of the Logger interface func (cl ConsoleLogger) Warningf(format string, v ...interface{}) { - file, line := fileAndLine(3) - vals := []interface{}{file, line} - vals = append(vals, v...) - log.Warningf("%v:%v] "+format, vals...) + log.WarningDepth(2, fmt.Sprintf(format, v...)) } // Errorf is part of the Logger interface func (cl ConsoleLogger) Errorf(format string, v ...interface{}) { - file, line := fileAndLine(3) - vals := []interface{}{file, line} - vals = append(vals, v...) - log.Errorf("%v:%v] "+format, vals...) + log.ErrorDepth(2, fmt.Sprintf(format, v...)) } // Printf is part of the Logger interface diff --git a/go/vt/logutil/throttled.go b/go/vt/logutil/throttled.go index 1ea612f27f1..867071f7b88 100644 --- a/go/vt/logutil/throttled.go +++ b/go/vt/logutil/throttled.go @@ -1,6 +1,7 @@ package logutil import ( + "fmt" "sync" "time" @@ -29,12 +30,12 @@ func NewThrottledLogger(name string, maxInterval time.Duration) *ThrottledLogger } } -type logFunc func(string, ...interface{}) +type logFunc func(int, ...interface{}) var ( - infof = log.Infof - warningf = log.Warningf - errorf = log.Errorf + infoDepth = log.InfoDepth + warningDepth = log.WarningDepth + errorDepth = log.ErrorDepth ) func (tl *ThrottledLogger) log(logF logFunc, format string, v ...interface{}) { @@ -45,7 +46,7 @@ func (tl *ThrottledLogger) log(logF logFunc, format string, v ...interface{}) { logWaitTime := tl.maxInterval - (now.Sub(tl.lastlogTime)) if logWaitTime < 0 { tl.lastlogTime = now - logF(tl.name+":"+format, v...) + logF(2, fmt.Sprintf(tl.name+":"+format, v...)) return } // If this is the first message to be skipped, start a goroutine @@ -55,7 +56,9 @@ func (tl *ThrottledLogger) log(logF logFunc, format string, v ...interface{}) { time.Sleep(d) tl.mu.Lock() defer tl.mu.Unlock() - logF("%v: skipped %v log messages", tl.name, tl.skippedCount) + // Because of the go func(), we lose the stack trace, + // so we just use the current line for this. + logF(0, fmt.Sprintf("%v: skipped %v log messages", tl.name, tl.skippedCount)) tl.skippedCount = 0 }(logWaitTime) } @@ -64,15 +67,15 @@ func (tl *ThrottledLogger) log(logF logFunc, format string, v ...interface{}) { // Infof logs an info if not throttled. func (tl *ThrottledLogger) Infof(format string, v ...interface{}) { - tl.log(infof, format, v...) + tl.log(infoDepth, format, v...) } // Warningf logs a warning if not throttled. func (tl *ThrottledLogger) Warningf(format string, v ...interface{}) { - tl.log(warningf, format, v...) + tl.log(warningDepth, format, v...) } // Errorf logs an error if not throttled. func (tl *ThrottledLogger) Errorf(format string, v ...interface{}) { - tl.log(errorf, format, v...) + tl.log(errorDepth, format, v...) } diff --git a/go/vt/logutil/throttled_test.go b/go/vt/logutil/throttled_test.go index f6b447f2f51..c8e0813c085 100644 --- a/go/vt/logutil/throttled_test.go +++ b/go/vt/logutil/throttled_test.go @@ -9,8 +9,8 @@ import ( func TestThrottledLogger(t *testing.T) { // Install a fake log func for testing. log := make(chan string) - infof = func(format string, args ...interface{}) { - log <- fmt.Sprintf(format, args...) + infoDepth = func(depth int, args ...interface{}) { + log <- fmt.Sprint(args...) } interval := 100 * time.Millisecond tl := NewThrottledLogger("name", interval) diff --git a/go/vt/wrangler/keyspace.go b/go/vt/wrangler/keyspace.go index 636ae3ff44f..51688314192 100644 --- a/go/vt/wrangler/keyspace.go +++ b/go/vt/wrangler/keyspace.go @@ -168,7 +168,7 @@ func (wr *Wrangler) MigrateServedTypes(ctx context.Context, keyspace, shard stri // rebuild the keyspace serving graph if there was no error if !rec.HasErrors() { - rec.RecordError(wr.RebuildKeyspaceGraph(ctx, keyspace, nil)) + rec.RecordError(wr.RebuildKeyspaceGraph(ctx, keyspace, cells)) } // Send a refresh to the tablets we just disabled, iff: