Skip to content

Commit

Permalink
pkg, tools: improve the log message (tikv#1636)
Browse files Browse the repository at this point in the history
* pkg,tools: improve the log message

Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch committed Jul 15, 2019
1 parent e3bf84d commit 3d780c0
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005"

[[constraint]]
branch = "master"
name = "github.com/pingcap/log"
branch = "master"

[[constraint]]
name = "go.uber.org/zap"
Expand Down
4 changes: 2 additions & 2 deletions pkg/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package etcdutil
import (
"context"
"crypto/tls"
"fmt"
"net/http"
"time"

Expand All @@ -25,6 +24,7 @@ import (
"github.com/coreos/etcd/pkg/types"
log "github.com/pingcap/log"
"github.com/pkg/errors"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -60,7 +60,7 @@ func CheckClusterID(localClusterID types.ID, um types.URLsMap, tlsConfig *tls.Co
trp.CloseIdleConnections()
if gerr != nil {
// Do not return error, because other members may be not ready.
log.Error(fmt.Sprintf("%v", gerr))
log.Error("failed to get cluster from remote", zap.Error(gerr))
continue
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/tempurl/tempurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

log "github.com/pingcap/log"
"go.uber.org/zap"
)

var (
Expand All @@ -42,12 +43,12 @@ func Alloc() string {
func tryAllocTestURL() string {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatal(fmt.Sprintf("%v", err))
log.Fatal("listen failed", zap.Error(err))
}
addr := fmt.Sprintf("http://%s", l.Addr())
err = l.Close()
if err != nil {
log.Fatal(fmt.Sprintf("%v", err))
log.Fatal("close failed", zap.Error(err))
}

testAddrMutex.Lock()
Expand Down
7 changes: 3 additions & 4 deletions server/api/redirector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package api

import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -95,21 +94,21 @@ func (p *customReverseProxies) ServeHTTP(w http.ResponseWriter, r *http.Request)

resp, err := p.client.Do(r)
if err != nil {
log.Error(fmt.Sprintf("%+v", err))
log.Error("request failed", zap.Error(err))
continue
}

b, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Error(fmt.Sprintf("%+v", err))
log.Error("request failed", zap.Error(err))
continue
}

copyHeader(w.Header(), resp.Header)
w.WriteHeader(resp.StatusCode)
if _, err := w.Write(b); err != nil {
log.Error(fmt.Sprintf("%+v", err))
log.Error("write failed", zap.Error(err))
continue
}

Expand Down
10 changes: 10 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ const (
defaultHeartbeatStreamRebindInterval = time.Minute

defaultLeaderPriorityCheckInterval = time.Minute

defaultDisableErrorVerbose = true
)

func adjustString(v *string, defValue string) {
Expand Down Expand Up @@ -395,6 +397,8 @@ func (c *Config) Adjust(meta *toml.MetaData) error {
return err
}

c.adjustLog(configMetaData.Child("log"))

adjustDuration(&c.heartbeatStreamBindInterval, defaultHeartbeatStreamRebindInterval)

adjustDuration(&c.leaderPriorityCheckInterval, defaultLeaderPriorityCheckInterval)
Expand All @@ -405,6 +409,12 @@ func (c *Config) Adjust(meta *toml.MetaData) error {
return nil
}

func (c *Config) adjustLog(meta *configMetaData) {
if !meta.IsDefined("disable-error-verbose") {
c.Log.DisableErrorVerbose = defaultDisableErrorVerbose
}
}

func (c *Config) clone() *Config {
cfg := &Config{}
*cfg = *c
Expand Down
3 changes: 2 additions & 1 deletion tools/pd-tso-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
log "github.com/pingcap/log"
pd "github.com/pingcap/pd/client"
"github.com/pkg/errors"
"go.uber.org/zap"
)

var (
Expand Down Expand Up @@ -55,7 +56,7 @@ func main() {
for i := 0; i < *concurrency; i++ {
_, _, err = pdCli.GetTS(ctx)
if err != nil {
log.Fatal(fmt.Sprintf("%v", err))
log.Fatal("get tso failed", zap.Error(err))
}
}

Expand Down
22 changes: 4 additions & 18 deletions vendor/github.com/pingcap/log/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion vendor/github.com/pingcap/log/log.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 30 additions & 7 deletions vendor/github.com/pingcap/log/zap_text_encoder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d780c0

Please sign in to comment.