Skip to content

Commit

Permalink
*: support --log-output=discard
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Apr 17, 2018
1 parent 1c44293 commit 18b3e45
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ See [security doc](https://github.com/coreos/etcd/blob/master/Documentation/op-g
- e.g. `--logger=zap --log-output=default` will log server operations with [JSON-encoded format](TODO) and writes logs to `os.Stderr` (detect systemd journald TODO).
- e.g. `--logger=zap --log-output=stderr` will log server operations with [JSON-encoded format](TODO) and writes logs to `os.Stderr` (bypass journald TODO).
- e.g. `--logger=zap --log-output=stdout` will log server operations with [JSON-encoded format](TODO) and writes logs to `os.Stdout` (bypass journald TODO).
- e.g. `--logger=zap --log-output=discard` will discard all server logs.

### Added: `embed`

Expand Down
9 changes: 8 additions & 1 deletion embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,25 @@ func (cfg *Config) setupLogging() error {
lcfg.OutputPaths = []string{"stderr"}
lcfg.ErrorOutputPaths = []string{"stderr"}
}

case "stderr":
lcfg.OutputPaths = []string{"stderr"}
lcfg.ErrorOutputPaths = []string{"stderr"}

case "stdout":
lcfg.OutputPaths = []string{"stdout"}
lcfg.ErrorOutputPaths = []string{"stdout"}
case "io-discard": // only for testing

case "discard": // only for testing
lcfg.OutputPaths = []string{}
lcfg.ErrorOutputPaths = []string{}
ignoreLog = true

default:
lcfg.OutputPaths = []string{cfg.LogOutput}
lcfg.ErrorOutputPaths = []string{cfg.LogOutput}
}

if cfg.Debug {
lcfg.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
grpc.EnableTracing = true
Expand Down
4 changes: 2 additions & 2 deletions embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestConfigFileOtherFields(t *testing.T) {
ptls,
true,
"zap",
"io-discard",
"discard",
false,
}

Expand Down Expand Up @@ -157,7 +157,7 @@ func mustCreateCfgFile(t *testing.T, b []byte) *os.File {
func TestAutoCompactionModeInvalid(t *testing.T) {
cfg := NewConfig()
cfg.Logger = "zap"
cfg.LogOutput = "io-discard"
cfg.LogOutput = "discard"
cfg.Debug = false
cfg.AutoCompactionMode = "period"
err := cfg.Validate()
Expand Down
4 changes: 2 additions & 2 deletions integration/embed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestEmbedEtcd(t *testing.T) {
for i := range tests {
tests[i].cfg = *embed.NewConfig()
tests[i].cfg.Logger = "zap"
tests[i].cfg.LogOutput = "io-discard"
tests[i].cfg.LogOutput = "discard"
tests[i].cfg.Debug = false

}
Expand Down Expand Up @@ -180,7 +180,7 @@ func newEmbedURLs(secure bool, n int) (urls []url.URL) {

func setupEmbedCfg(cfg *embed.Config, curls []url.URL, purls []url.URL) {
cfg.Logger = "zap"
cfg.LogOutput = "io-discard"
cfg.LogOutput = "discard"
cfg.Debug = false

cfg.ClusterState = "new"
Expand Down
2 changes: 1 addition & 1 deletion snapshot/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestSnapshotV3RestoreMultiMemberAdd(t *testing.T) {

cfg := embed.NewConfig()
cfg.Logger = "zap"
cfg.LogOutput = "io-discard"
cfg.LogOutput = "discard"
cfg.Debug = false
cfg.Name = "3"
cfg.InitialClusterToken = testClusterTkn
Expand Down
6 changes: 3 additions & 3 deletions snapshot/v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestSnapshotV3RestoreSingle(t *testing.T) {

cfg := embed.NewConfig()
cfg.Logger = "zap"
cfg.LogOutput = "io-discard"
cfg.LogOutput = "discard"
cfg.Debug = false
cfg.Name = "s1"
cfg.InitialClusterToken = testClusterTkn
Expand Down Expand Up @@ -153,7 +153,7 @@ func createSnapshotFile(t *testing.T, kvs []kv) string {

cfg := embed.NewConfig()
cfg.Logger = "zap"
cfg.LogOutput = "io-discard"
cfg.LogOutput = "discard"
cfg.Debug = false
cfg.Name = "default"
cfg.ClusterState = "new"
Expand Down Expand Up @@ -220,7 +220,7 @@ func restoreCluster(t *testing.T, clusterN int, dbPath string) (
for i := 0; i < clusterN; i++ {
cfg := embed.NewConfig()
cfg.Logger = "zap"
cfg.LogOutput = "io-discard"
cfg.LogOutput = "discard"
cfg.Debug = false
cfg.Name = fmt.Sprintf("%d", i)
cfg.InitialClusterToken = testClusterTkn
Expand Down

0 comments on commit 18b3e45

Please sign in to comment.