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