Browse Source

fix CI lint problem.

topic
tinatwang 5 years ago
parent
commit
04f2ec41e8
  1. 2
      bench/main.go
  2. 11
      dtmcli/logger/log.go
  3. 2
      dtmsvr/config/config.go
  4. 2
      dtmsvr/svr.go

2
bench/main.go

@ -38,7 +38,7 @@ func main() {
if len(conf.Log.Outputs) != 0 { if len(conf.Log.Outputs) != 0 {
outputs = strings.Split(conf.Log.Outputs, "|") outputs = strings.Split(conf.Log.Outputs, "|")
} }
logger.InitLog(conf.Log.Level, outputs, conf.Log.LogRotationEnable, conf.Log.LogRotationConfigJson) logger.InitLog(conf.Log.Level, outputs, conf.Log.LogRotationEnable, conf.Log.LogRotationConfigJSON)
if busi.BusiConf.Driver != "" { if busi.BusiConf.Driver != "" {
dtmcli.SetCurrentDBType(busi.BusiConf.Driver) dtmcli.SetCurrentDBType(busi.BusiConf.Driver)
svr.PrepareBenchDB() svr.PrepareBenchDB()

11
dtmcli/logger/log.go

@ -17,6 +17,7 @@ import (
var logger Logger var logger Logger
// DefaultLogOutput is the default configuration for log output.
const ( const (
DefaultLogOutput = "default" DefaultLogOutput = "default"
StdErrLogOutput = "stderr" StdErrLogOutput = "stderr"
@ -78,7 +79,7 @@ func InitLog(level string, outputs []string, logRotationEnable int64, logRotateC
// setup log rotation // setup log rotation
if logRotationEnable != 0 { if logRotationEnable != 0 {
_ = setupLogRotation(outputs, logRotateConfigJSON) setupLogRotation(outputs, logRotateConfigJSON)
} }
config := loadConfig(level) config := loadConfig(level)
@ -97,7 +98,7 @@ func (lumberjackSink) Sync() error {
} }
// setupLogRotation initializes log rotation for a single file path target. // setupLogRotation initializes log rotation for a single file path target.
func setupLogRotation(logOutputs []string, logRotateConfigJSON string) error { func setupLogRotation(logOutputs []string, logRotateConfigJSON string) {
var lumberjackSink lumberjackSink var lumberjackSink lumberjackSink
outputFilePaths := 0 outputFilePaths := 0
for _, v := range logOutputs { for _, v := range logOutputs {
@ -110,11 +111,11 @@ func setupLogRotation(logOutputs []string, logRotateConfigJSON string) error {
} }
// log rotation requires file target // log rotation requires file target
if len(logOutputs) == 1 && outputFilePaths == 0 { if len(logOutputs) == 1 && outputFilePaths == 0 {
FatalIfError(fmt.Errorf("log outputs requires a single file path when LogRotationConfigJson is defined")) FatalIfError(fmt.Errorf("log outputs requires a single file path when LogRotationConfigJSON is defined"))
} }
// support max 1 file target for log rotation // support max 1 file target for log rotation
if outputFilePaths > 1 { if outputFilePaths > 1 {
FatalIfError(fmt.Errorf("log outputs requires a single file path when LogRotationConfigJson is defined")) FatalIfError(fmt.Errorf("log outputs requires a single file path when LogRotationConfigJSON is defined"))
} }
if err := json.Unmarshal([]byte(logRotateConfigJSON), &lumberjackSink); err != nil { if err := json.Unmarshal([]byte(logRotateConfigJSON), &lumberjackSink); err != nil {
@ -132,7 +133,7 @@ func setupLogRotation(logOutputs []string, logRotateConfigJSON string) error {
return &lumberjackSink, nil return &lumberjackSink, nil
}) })
FatalIfError(err) FatalIfError(err)
return nil return
} }
func loadConfig(logLevel string) zap.Config { func loadConfig(logLevel string) zap.Config {

2
dtmsvr/config/config.go

@ -34,7 +34,7 @@ type Log struct {
Level string `yaml:"Level" default:"info"` Level string `yaml:"Level" default:"info"`
Outputs string `yaml:"Outputs" default:""` Outputs string `yaml:"Outputs" default:""`
LogRotationEnable int64 `yaml:"LogRotationEnable" default:"0"` LogRotationEnable int64 `yaml:"LogRotationEnable" default:"0"`
LogRotationConfigJson string `yaml:"LogRotationConfigJson" default:""` LogRotationConfigJSON string `yaml:"LogRotationConfigJSON" default:""`
} }
// Store defines storage relevant info // Store defines storage relevant info

2
dtmsvr/svr.go

@ -31,7 +31,7 @@ func StartSvr() {
if len(conf.Log.Outputs) != 0 { if len(conf.Log.Outputs) != 0 {
outputs = strings.Split(conf.Log.Outputs, "|") outputs = strings.Split(conf.Log.Outputs, "|")
} }
logger.InitLog(conf.Log.Level, outputs, conf.Log.LogRotationEnable, conf.Log.LogRotationConfigJson) logger.InitLog(conf.Log.Level, outputs, conf.Log.LogRotationEnable, conf.Log.LogRotationConfigJSON)
dtmcli.GetRestyClient().SetTimeout(time.Duration(conf.RequestTimeout) * time.Second) dtmcli.GetRestyClient().SetTimeout(time.Duration(conf.RequestTimeout) * time.Second)
dtmgrpc.AddUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { dtmgrpc.AddUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {

Loading…
Cancel
Save