Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back original NewZapCoreLoggerBuilder api. #12973

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.4.0...v3.5.0) and
- Turned on [--pre-vote by default](https://github.com/etcd-io/etcd/pull/12770). Should prevent disrupting RAFT leader by an individual member.
- [ETCD_CLIENT_DEBUG env](https://github.com/etcd-io/etcd/pull/12786): Now supports log levels (debug, info, warn, error, dpanic, panic, fatal). Only when set, overrides application-wide grpc logging settings.
- [Embed Etcd.Close()](https://github.com/etcd-io/etcd/pull/12828) needs to called exactly once and closes Etcd.Err() stream.
- [Embed Etcd does not override global/grpc logger](https://github.com/etcd-io/etcd/pull/12861) be default any longer. If desired, please call `embed.Config::SetupGlobalLoggers()` explicitly.
- [Embed Etcd does not override global/grpc logger](https://github.com/etcd-io/etcd/pull/12861) be default any longer. If desired, please call `embed.Config::SetupGlobalLoggers()` explicitly.
- [Embed Etcd custom logger should be configured using simpler builder `NewZapLoggerBuilder`](https://github.com/etcd-io/etcd/pull/12973).
- Client errors of `context cancelled` or `context deadline exceeded` are exposed as `codes.Canceled` and `codes.DeadlineExceeded`, instead of `codes.Unknown`.


### Storage format changes
- [WAL log's snapshots persists raftpb.ConfState](https://github.com/etcd-io/etcd/pull/12735)
- [Backend persists raftpb.ConfState](https://github.com/etcd-io/etcd/pull/12962) in the `meta` bucket `confState` key.
Expand Down
31 changes: 14 additions & 17 deletions server/embed/config_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,11 @@ func (cfg *Config) setupLogging() error {
copied = logutil.MergeOutputPaths(copied)
copied.Level = zap.NewAtomicLevelAt(logutil.ConvertToZapLevel(cfg.LogLevel))
if cfg.ZapLoggerBuilder == nil {
cfg.ZapLoggerBuilder = func(c *Config) error {
c.loggerMu.Lock()
defer c.loggerMu.Unlock()
var err error
c.logger, err = copied.Build()
if err != nil {
return err
}
return nil
lg, err := copied.Build()
if err != nil {
return err
}
cfg.ZapLoggerBuilder = NewZapLoggerBuilder(lg)
}
} else {
if len(cfg.LogOutputs) > 1 {
Expand All @@ -139,12 +134,7 @@ func (cfg *Config) setupLogging() error {
lvl,
)
if cfg.ZapLoggerBuilder == nil {
cfg.ZapLoggerBuilder = func(c *Config) error {
c.loggerMu.Lock()
defer c.loggerMu.Unlock()
c.logger = zap.New(cr, zap.AddCaller(), zap.ErrorOutput(syncer))
return nil
}
cfg.ZapLoggerBuilder = NewZapLoggerBuilder(zap.New(cr, zap.AddCaller(), zap.ErrorOutput(syncer)))
}
}

Expand Down Expand Up @@ -190,8 +180,9 @@ func (cfg *Config) setupLogging() error {
return nil
}

// NewZapCoreLoggerBuilder generates a zap core logger builder.
func NewZapCoreLoggerBuilder(lg *zap.Logger) func(*Config) error {
// NewZapLoggerBuilder generates a zap logger builder that sets given loger
// for embedded etcd.
func NewZapLoggerBuilder(lg *zap.Logger) func(*Config) error {
return func(cfg *Config) error {
cfg.loggerMu.Lock()
defer cfg.loggerMu.Unlock()
Expand All @@ -200,6 +191,12 @@ func NewZapCoreLoggerBuilder(lg *zap.Logger) func(*Config) error {
}
}

// NewZapCoreLoggerBuilder - is a deprecated setter for the logger.
// Deprecated: Use simpler NewZapLoggerBuilder. To be removed in etcd-3.6.
func NewZapCoreLoggerBuilder(lg *zap.Logger, _ zapcore.Core, _ zapcore.WriteSyncer) func(*Config) error {
return NewZapLoggerBuilder(lg)
}

// SetupGlobalLoggers configures 'global' loggers (grpc, zapGlobal) based on the cfg.
//
// The method is not executed by embed server by default (since 3.5) to
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewEmbedConfig(t testing.TB, name string) *embed.Config {
cfg := embed.NewConfig()
cfg.Name = name
lg := zaptest.NewLogger(t, zaptest.Level(zapcore.InfoLevel)).Named(cfg.Name)
cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(lg)
cfg.ZapLoggerBuilder = embed.NewZapLoggerBuilder(lg)
cfg.Dir = t.TempDir()
return cfg
}
Expand Down