mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
*: use default log configuration for server
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
This commit is contained in:
parent
52391e3be7
commit
8d1a62e7ef
@ -21,7 +21,6 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"go.etcd.io/etcd/pkg/logutil"
|
||||
@ -131,77 +130,55 @@ func (cfg *Config) setupLogging() error {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use zapcore to support more features?
|
||||
lcfg := zap.Config{
|
||||
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
|
||||
Development: false,
|
||||
Sampling: &zap.SamplingConfig{
|
||||
Initial: 100,
|
||||
Thereafter: 100,
|
||||
},
|
||||
Encoding: "json",
|
||||
EncoderConfig: zap.NewProductionEncoderConfig(),
|
||||
|
||||
OutputPaths: make([]string, 0),
|
||||
ErrorOutputPaths: make([]string, 0),
|
||||
}
|
||||
|
||||
outputPaths, errOutputPaths := make(map[string]struct{}), make(map[string]struct{})
|
||||
outputPaths, errOutputPaths := make([]string, 0), make([]string, 0)
|
||||
isJournal := false
|
||||
for _, v := range cfg.LogOutputs {
|
||||
switch v {
|
||||
case DefaultLogOutput:
|
||||
outputPaths[StdErrLogOutput] = struct{}{}
|
||||
errOutputPaths[StdErrLogOutput] = struct{}{}
|
||||
outputPaths = append(outputPaths, StdErrLogOutput)
|
||||
errOutputPaths = append(errOutputPaths, StdErrLogOutput)
|
||||
|
||||
case JournalLogOutput:
|
||||
isJournal = true
|
||||
|
||||
case StdErrLogOutput:
|
||||
outputPaths[StdErrLogOutput] = struct{}{}
|
||||
errOutputPaths[StdErrLogOutput] = struct{}{}
|
||||
outputPaths = append(outputPaths, StdErrLogOutput)
|
||||
errOutputPaths = append(errOutputPaths, StdErrLogOutput)
|
||||
|
||||
case StdOutLogOutput:
|
||||
outputPaths[StdOutLogOutput] = struct{}{}
|
||||
errOutputPaths[StdOutLogOutput] = struct{}{}
|
||||
outputPaths = append(outputPaths, StdOutLogOutput)
|
||||
errOutputPaths = append(errOutputPaths, StdOutLogOutput)
|
||||
|
||||
default:
|
||||
outputPaths[v] = struct{}{}
|
||||
errOutputPaths[v] = struct{}{}
|
||||
outputPaths = append(outputPaths, v)
|
||||
errOutputPaths = append(errOutputPaths, v)
|
||||
}
|
||||
}
|
||||
|
||||
if !isJournal {
|
||||
for v := range outputPaths {
|
||||
lcfg.OutputPaths = append(lcfg.OutputPaths, v)
|
||||
}
|
||||
for v := range errOutputPaths {
|
||||
lcfg.ErrorOutputPaths = append(lcfg.ErrorOutputPaths, v)
|
||||
}
|
||||
sort.Strings(lcfg.OutputPaths)
|
||||
sort.Strings(lcfg.ErrorOutputPaths)
|
||||
copied := logutil.AddOutputPaths(logutil.DefaultZapLoggerConfig, outputPaths, errOutputPaths)
|
||||
|
||||
if cfg.Debug {
|
||||
lcfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
copied.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
grpc.EnableTracing = true
|
||||
}
|
||||
if cfg.ZapLoggerBuilder == nil {
|
||||
cfg.ZapLoggerBuilder = func(c *Config) error {
|
||||
var err error
|
||||
c.logger, err = lcfg.Build()
|
||||
c.logger, err = copied.Build()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.loggerMu.Lock()
|
||||
defer c.loggerMu.Unlock()
|
||||
c.loggerConfig = &lcfg
|
||||
c.loggerConfig = &copied
|
||||
c.loggerCore = nil
|
||||
c.loggerWriteSyncer = nil
|
||||
grpcLogOnce.Do(func() {
|
||||
// debug true, enable info, warning, error
|
||||
// debug false, only discard info
|
||||
var gl grpclog.LoggerV2
|
||||
gl, err = logutil.NewGRPCLoggerV2(lcfg)
|
||||
gl, err = logutil.NewGRPCLoggerV2(copied)
|
||||
if err == nil {
|
||||
grpclog.SetLoggerV2(gl)
|
||||
}
|
||||
@ -233,7 +210,7 @@ func (cfg *Config) setupLogging() error {
|
||||
// WARN: do not change field names in encoder config
|
||||
// journald logging writer assumes field names of "level" and "caller"
|
||||
cr := zapcore.NewCore(
|
||||
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
|
||||
zapcore.NewJSONEncoder(logutil.DefaultZapLoggerConfig.EncoderConfig),
|
||||
syncer,
|
||||
lvl,
|
||||
)
|
||||
@ -253,10 +230,12 @@ func (cfg *Config) setupLogging() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err := cfg.ZapLoggerBuilder(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logTLSHandshakeFailure := func(conn *tls.Conn, err error) {
|
||||
state := conn.ConnectionState()
|
||||
remoteAddr := conn.RemoteAddr().String()
|
||||
|
@ -151,19 +151,7 @@ func newGRPCProxyStartCommand() *cobra.Command {
|
||||
func startGRPCProxy(cmd *cobra.Command, args []string) {
|
||||
checkArgs()
|
||||
|
||||
lcfg := zap.Config{
|
||||
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
|
||||
Development: false,
|
||||
Sampling: &zap.SamplingConfig{
|
||||
Initial: 100,
|
||||
Thereafter: 100,
|
||||
},
|
||||
Encoding: "json",
|
||||
EncoderConfig: zap.NewProductionEncoderConfig(),
|
||||
|
||||
OutputPaths: []string{"stderr"},
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
}
|
||||
lcfg := logutil.DefaultZapLoggerConfig
|
||||
if grpcProxyDebug {
|
||||
lcfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
|
||||
grpc.EnableTracing = true
|
||||
|
@ -58,20 +58,8 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
lcfg := &zap.Config{
|
||||
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
|
||||
Development: false,
|
||||
Sampling: &zap.SamplingConfig{
|
||||
Initial: 100,
|
||||
Thereafter: 100,
|
||||
},
|
||||
Encoding: "json",
|
||||
EncoderConfig: zap.NewProductionEncoderConfig(),
|
||||
|
||||
OutputPaths: []string{"stderr"},
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
}
|
||||
lg, err := logutil.NewRaftLogger(lcfg)
|
||||
lcfg := logutil.DefaultZapLoggerConfig
|
||||
lg, err := logutil.NewRaftLogger(&lcfg)
|
||||
if err != nil {
|
||||
log.Fatalf("cannot create raft logger %v", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user