Skip to content
Merged

Log #587

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions go/vt/logutil/console_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 12 additions & 9 deletions go/vt/logutil/throttled.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logutil

import (
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -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{}) {
Expand All @@ -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
Expand All @@ -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)
}
Expand All @@ -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...)
}
4 changes: 2 additions & 2 deletions go/vt/logutil/throttled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/wrangler/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down