Please answer these questions before submitting your issue. Thanks!
I'm working on tikv client benchmark.
But I realize that logrus.SetLevel() will not take effect caused by the vendor.
If here is any way for me to set the log level for tikv go client client.
...
import "github.com/Sirupsen/logrus"
...
func main() {
...
logrus.SetLevel(logrus.ErrorLevel)
...
}
nothing happened
tidb-server -V or run select tidb_version(); on TiDB)?master branch
There is a config.toml.example file in the tidb/config dir, https://github.com/pingcap/tidb/blob/master/config/config.toml.example
You can change here as you like
[log]
# Log level: debug, info, warn, error, fatal.
level = "info"
and start TiDB with
./tidb-server -config config.toml.example
@tiancaiamao Emmm
I mean How to set log level in KV client
There are benchkv file here https://github.com/pingcap/tidb/blob/master/cmd/benchkv/main.go
You can have a look.
func main() {
flag.Parse()
log.SetLevel(log.ErrorLevel) // Change this to whatever you like
Init()
@tiancaiamao yes, but it won't take effect outside this repo. Cause go will search _vendor_ for this demo, and this log.SetLevel() only will take effect if your main.go is under $GOPATH/github.com/pingcap/tidb/
This means
log.SetLevel(log.ErrorLevel) // Change this to whatever you like
only changed the vendor/logrus log level.
You want to set log level for your benchmark program, of set log level for TiDB ? @arthurkiller
I get my own repo for tikv benchmark, and I import tikv client from github.com/pingcap/tidb/store/tikv. But I can't set the log level for tikv client.
So, the problem is tikv client log nothing.
Whether you set log level or not, does not affect the output...
correct
Best regards
✉️✉️✉️✉️✉️✉️✉️✉️✉️✉️✉️✉️✉️✉️
Arthur lee
Sent from my iPhone
On Apr 12, 2018, at 7:57 PM, tiancaiamao notifications@github.com wrote:
So, the problem is tikv client log nothing.
Whether you set log level or not, does not affect the output...—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
@tiancaiamao why closed? this issue is not solved yet?
So, the problem is tikv client log nothing.
tikv client default log level is info, the out puts has mixed up
Sorry, I don't get the point. @arthurkiller
What do you really want to do? what's the log output do you expected? Is the output by your program or by the tikv client library?
Would you please show me your program source code?
@tiancaiamao ...抱歉表达能力有限. 我换个方式...
我自己写了 benchmark 程序用于测试 tivk, 使用的tikv客户端(这个客户端是指封装 get put scan 的客户端)是 /tidb/store 下面的 client.
现在这个客户端没有问题,但是 log level 没法改变 (无法通过 logrus.SetLevel() 这个函数生效). 因为我的 bench 程序独立在 tidb 这个 repo 外面.
而你提到的 benchkv 那个 client 可以通过 logrus.SetLevel 生效的原因是, 这个代码位于 tidb 的 vendor 下面, 依赖走的是 tidb 的 vendor.
至于你说的通过 配置文件方式, 我理解的是设置了 tidb 的 log. 但是我只用到了 tivk 的 client.
我觉得, 既然依赖已经通过 vendor 管理, 而且使用的是全局的 log 对象(通过 import log 的方式) , 那么最好是能够暴露一个set log level 的接口
如果有其他的生效方式, 烦请指出.. 如果没有, 我可以提交一个 pr
So, show me the code or your repo, I can know what happened.
A suspicious place, you should
import "github.com/sirupsen/logrus"
not
import "github.com/Sirupsen/logrus"
package main
import (
"context"
"flag"
"fmt"
"io"
"math/rand"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/Sirupsen/logrus"
"github.com/arthurkiller/perfm"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/store/tikv"
)
var (
num int64
rd *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
lock sync.Mutex
addr *string = flag.String("addr", "10.10.34.77:2379,10.10.34.78:2379,10.10.32.223:2379", "indecate the pd cluster address")
keysize *int = flag.Int("key", 1024, "set the key size for test")
valuesize *int = flag.Int("value", 10240, "set the vlaue size for test")
scanlimit *int = flag.Int("limit", 1024, "set the limit for scan")
c *int = flag.Int("C", 100, "concurrency number for benchmark")
t *int = flag.Int("T", 30, "benchmark duration in seconds")
n *int = flag.Int("N", 0, "benchmark total requests count, default is zero will disable total mode")
)
// iwjob do increase + write in a transection
type iwjob struct {
ident int64
store kv.Storage
key, value []byte
}
func (j *iwjob) Copy() (perfm.Job, error) {
jc := *j
jc.ident = atomic.AddInt64(&num, 1)
var err error
driver := tikv.Driver{}
jc.store, err = driver.Open("tikv://" + *addr + "?cluster=1")
if err != nil {
return nil, err
}
jc.value = make([]byte, *valuesize)
return &jc, nil
}
func (j *iwjob) Pre() (err error) {
j.key = []byte(fmt.Sprintf("iwbench_%d", j.ident))
lock.Lock()
defer lock.Unlock()
io.ReadFull(rd, j.value)
return nil
}
func (j *iwjob) Do() error {
tx, err := j.store.Begin()
if err != nil {
return err
}
_, err = kv.IncInt64(tx, kv.Key([]byte("index")), 1)
if err != nil {
return err
}
if err = tx.Set(kv.Key([]byte(append([]byte("value_"), byte(j.ident)))), j.value); err != nil {
return err
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err = tx.Commit(ctx); err != nil {
return tx.Rollback()
}
return nil
}
func (j *iwjob) After() {
//j.store.Close()
}
func main() {
logrus.SetLevel(logrus.ErrorLevel) // take no effect
flag.Parse()
if !flag.Parsed() {
flag.Usage()
return
}
perfm := perfm.New(perfm.WithBinsNumber(15), perfm.WithParallel(*c), perfm.WithDuration(*t), perfm.WithNumber(*n))
fmt.Println("do iw bench")
perfm.Regist(&iwjob{})
perfm.Start()
perfm.Wait()
}
@tiancaiamao I tried import "github.com/Sirupsen/logrus" but nothing changed

@arthurkiller It looks like logs from https://github.com/pingcap/pd .
@jackysp PD is not on this host...
Really a confusing problem, hhh
举一个最简单的例子,
$GOPATH/src/github.com/pingcap/tidb/cmd/benchraw 这个项目我直接 go build , 执行没有 info log 输出
将, main.go copy 到 $GOPTAH/src/demo 下编译, 就会有 log 输出

你们可以试一下, 然后这个问题就能理解了
@tiancaiamao 看下这个
Try this one "github.com/sirupsen/logrus" ? @arthurkiller
@tiancaiamao have a look on my last comment
Oh, I see...
Your GOPATH/src/github.com/sirupsen/logrus is different from which in tidb/vendor
Go to GOPATH/src/github.com/sirupsen/logrus, checkout to that git hash and retry.
[[projects]]
name = "github.com/sirupsen/logrus"
packages = ["."]
revision = "ba1b36c82c5e05c4f912a88eab0dcd91a171688f"
version = "v0.11.5"


@tiancaiamao noting.
Caused the vendor has its own logrus. And go __will not__ recognize those two logrus(one in vendor , one in GOPATH) as one
I'm on go 1.10.1
sirupsen/logrus, not Sirupsen/logrus....
It's to better to remove Sirupsen/logrus directory
Upgrade your $GOPATH/src/github.com/pingcap/pd/pd-client to master, too.
As for me.
I will expose log level controller. Cause this repo use the global log instance and it was managed my logrus in vendor
sirupsen/logrus, not Sirupsen/logrus....
changed, but it will not take effect(go import is not case-sensitive).
@tiancaiamao Bro, If u do this. You will see what will happen...
举一个最简单的例子,
$GOPATH/src/github.com/pingcap/tidb/cmd/benchraw 这个项目我直接 go build , 执行没有 info log 输出
将, main.go copy 到 $GOPTAH/src/demo 下编译, 就会有 log 输出
image
你们可以试一下, 然后这个问题就能理解了
@tiancaiamao 看下这个
I am doing the same thing:
move the benchraw outside the repo, add some testcase, run the bench
这个问题很难理解么? [捂脸]
$GOPATH/src/github.com/pingcap/tidb/cmd/benchraw 这个项目我直接 go build,执行没有 info log 输出
This case, Go use $GOPATH/src/github.com/pingcap/tidb/vendor/github.com/sirupsen to build the binary.
将, main.go copy 到 $GOPTAH/src/demo 下编译, 就会有 log 输出
In this case, Go use $GOPATH/src/github.com/sirupsen to build the binary.
go import is not case-sensitive
It's Mac file system that case-insensitive, not Go.
sirupsen/logrus, not Sirupsen/logrus....
It's to better to remove Sirupsen/logrus directory
Upgrade your $GOPATH/src/github.com/pingcap/pd/pd-client to master, too.
It doesn't work?
We provide vendor to get rid of user's environment, and we use Makefile to control the build processing.
If user break the rule, we can't provide a repeatable build and it's very hard to digest the problem.
It's Mac file system that case-insensitive, not Go.
I have change the path name into lowercase, still can't help
If here is any solution setting log level freely for main.go outside tidb's vendor
Don't change the path name... remove it !
After I remove the log, how could I set the tikv client log level in my code?

We provide vendor to get rid of user's environment, and we use Makefile to control the build processing.
If user break the rule, we can't provide a repeatable build and it's very hard to digest the problem.
right, vendor is used to unique dependencies. But we are here talking about __how to use logrus__
In tidb's way, the global log instance is initialized when import logrus, and all the log action point to the same(and only one) log instance.
It make's log become clean and unique. But the log instance will be a internal instance which can not be set by SDK user.
I guess, You are pushing me to build my benchmark code under tikv project. Right?
I just a tikv SDK user. [shrug]
If you remove "sirupsen/logrus", and reinstall it ... You may find it actually works.
I usually get into trouble with my computer, so I reboot it, it work!
I usually get into trouble with my computer, so I reboot it, it work!
Ridiculous.
I thing this problem is really clear


@ngaut @shenli Help wanted. It's really a slice of problem.
@arthurkiller
You can try to add a function SetLogLevel in a package under tidb, then call that function in your benchmark code.
@arthurkiller
There is a package util/logutil in tidb, you can try this code.
logutil.InitLogger(&logutil.LogConfig{
Level: logLevel,
})
Modify "$GOPATH/src/github.com/sirupsen/exported.go"
func SetLevel(level Level) {
fmt.Println("SetLevel from GOPATH!!!!!")
std.mu.Lock()
defer std.mu.Unlock()
std.Level = level
}
// Infoln logs a message at level Info on the standard logger.
func Infoln(args ...interface{}) {
fmt.Println("Infoln from GOPATH!!!!!!!")
std.Infoln(args...)
}
And modify "$GOPATH/src/github.com/pingcap/tidb/vendor/github.com/sirupsen/logrus/exported.go"
func SetLevel(level Level) {
fmt.Println("SetLevel from TiDB vendor!!!!!")
std.mu.Lock()
defer std.mu.Unlock()
std.Level = level
}
// Infoln logs a message at level Info on the standard logger.
func Infoln(args ...interface{}) {
fmt.Println("Infoln from TiDB vendor!!!!!!!")
std.Infoln(args...)
}
I guess it maybe helpful for debugging the problem. @arthurkiller
@coocood Thx for reply, I will try, and would you welcome a PR about this?
@tiancaiamao You didn't get the point I think. Anyway thx for your help.
@arthurkiller
We don't need a PR, the logutil.InitLogger function is already there, you can use it directly.
Get it, Closed