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

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

Author:    Weny Xu <wenymedia@gmail.com>
Date:      Sat Nov 27 10:37:00 2021 +0900
This commit is contained in:
Weny Xu 2021-12-22 12:58:33 +09:00 committed by GitHub
parent b82206ff30
commit 8b8fdd5adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -135,6 +135,7 @@ To save the hard state is also very easy, just update peer storages `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

View File

@ -2,6 +2,7 @@ package config
import (
"fmt"
"os"
"time"
"github.com/pingcap-incubator/tinykv/log"
@ -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,
@ -83,7 +92,7 @@ func NewDefaultConfig() *Config {
func NewTestConfig() *Config {
return &Config{
LogLevel: "info",
LogLevel: getLogLevel(),
Raft: true,
RaftBaseTickInterval: 50 * time.Millisecond,
RaftHeartbeatTicks: 2,