Skip to content

Commit

Permalink
feat(kv/config): support to customize log level via env (talent-plan#324
Browse files Browse the repository at this point in the history
)

* feat(kv/config): support to customize log level via env

Author:    Weny Xu <[email protected]>
Date:      Sat Nov 27 10:37:00 2021 +0900
  • Loading branch information
WenyXu authored Dec 22, 2021
1 parent b82206f commit 8b8fdd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/project2-RaftKV.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ To save the hard state is also very easy, just update peer storage’s `RaftLoca
>
> - Use `WriteBatch` to save these states at once.
> - See other functions at `peer_storage.go` for how to read and write these states.
> - Set the environment variable LOG_LEVEL=debug which may help you in debugging, see also the all available [log levels](../log/log.go).
### Implement Raft ready process

Expand Down
13 changes: 11 additions & 2 deletions kv/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"fmt"
"os"
"time"

"github.com/pingcap-incubator/tinykv/log"
Expand Down Expand Up @@ -60,11 +61,19 @@ const (
MB uint64 = 1024 * 1024
)

func getLogLevel() (logLevel string) {
logLevel = "info"
if l := os.Getenv("LOG_LEVEL"); len(l) != 0 {
logLevel = l
}
return
}

func NewDefaultConfig() *Config {
return &Config{
SchedulerAddr: "127.0.0.1:2379",
StoreAddr: "127.0.0.1:20160",
LogLevel: "info",
LogLevel: getLogLevel(),
Raft: true,
RaftBaseTickInterval: 1 * time.Second,
RaftHeartbeatTicks: 2,
Expand All @@ -83,7 +92,7 @@ func NewDefaultConfig() *Config {

func NewTestConfig() *Config {
return &Config{
LogLevel: "info",
LogLevel: getLogLevel(),
Raft: true,
RaftBaseTickInterval: 50 * time.Millisecond,
RaftHeartbeatTicks: 2,
Expand Down

0 comments on commit 8b8fdd5

Please sign in to comment.