diff --git a/pkg/util/log/log_bridge.go b/pkg/util/log/log_bridge.go index 09ae9c253cc1..fe6f299eaf54 100644 --- a/pkg/util/log/log_bridge.go +++ b/pkg/util/log/log_bridge.go @@ -16,13 +16,19 @@ import ( "fmt" stdLog "log" "strconv" + "strings" ) // NewStdLogger creates a *stdLog.Logger that forwards messages to the // CockroachDB logs with the specified severity. // -// The prefix appears at the beginning of each generated log line. +// The prefix should be the path of the package for which this logger +// is used. The prefix will be concatenated directly with the name +// of the file that triggered the logging. func NewStdLogger(severity Severity, prefix string) *stdLog.Logger { + if prefix != "" && !strings.HasSuffix(prefix, "/") { + prefix += "/" + } return stdLog.New(logBridge(severity), prefix, stdLog.Lshortfile) } @@ -67,7 +73,9 @@ func (lb logBridge) Write(b []byte) (n int, err error) { if parts := bytes.SplitN(b, []byte{':'}, 3); len(parts) != 3 || len(parts[0]) < 1 || len(parts[2]) < 1 { entry.Message = fmt.Sprintf("bad log format: %s", b) } else { - entry.File = string(parts[0]) + // We use a "(gostd)" prefix so that these log lines correctly point + // to the go standard library instead of our own source directory. + entry.File = "(gostd) " + string(parts[0]) entry.Message = string(parts[2][1 : len(parts[2])-1]) // skip leading space and trailing newline entry.Line, err = strconv.ParseInt(string(parts[1]), 10, 64) if err != nil { diff --git a/pkg/util/netutil/net.go b/pkg/util/netutil/net.go index 3a852fa064dd..aad4514fd561 100644 --- a/pkg/util/netutil/net.go +++ b/pkg/util/netutil/net.go @@ -54,7 +54,7 @@ func ListenAndServeGRPC( return ln, nil } -var httpLogger = log.NewStdLogger(log.Severity_ERROR, "httpLogger") +var httpLogger = log.NewStdLogger(log.Severity_ERROR, "net/http") // Server is a thin wrapper around http.Server. See MakeServer for more detail. type Server struct {