mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
server: Use default logging configuration instead of zap production one
This fixes problem where logs json changes format of timestamp.
This commit is contained in:
@@ -175,6 +175,7 @@ type etcdProcessClusterConfig struct {
|
||||
v2deprecation string
|
||||
|
||||
rollingStart bool
|
||||
logLevel string
|
||||
}
|
||||
|
||||
// newEtcdProcessCluster launches a new cluster from etcd processes, returning
|
||||
@@ -315,6 +316,10 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs(tb testing.TB) []*
|
||||
args = append(args, "--v2-deprecation", cfg.v2deprecation)
|
||||
}
|
||||
|
||||
if cfg.logLevel != "" {
|
||||
args = append(args, "--log-level", cfg.logLevel)
|
||||
}
|
||||
|
||||
etcdCfgs[i] = &etcdServerProcessConfig{
|
||||
lg: lg,
|
||||
execPath: cfg.execPath,
|
||||
|
||||
76
tests/e2e/zap_logging_test.go
Normal file
76
tests/e2e/zap_logging_test.go
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright 2022 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !cov
|
||||
// +build !cov
|
||||
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestServerJsonLogging(t *testing.T) {
|
||||
BeforeTest(t)
|
||||
|
||||
epc, err := newEtcdProcessCluster(t, &etcdProcessClusterConfig{
|
||||
clusterSize: 1,
|
||||
initialToken: "new",
|
||||
logLevel: "debug",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("could not start etcd process cluster (%v)", err)
|
||||
}
|
||||
logs := epc.procs[0].Logs()
|
||||
time.Sleep(time.Second)
|
||||
if err = epc.Close(); err != nil {
|
||||
t.Fatalf("error closing etcd processes (%v)", err)
|
||||
}
|
||||
var entry logEntry
|
||||
lines := logs.Lines()
|
||||
if len(lines) == 0 {
|
||||
t.Errorf("Expected at least one log line")
|
||||
}
|
||||
for _, line := range lines {
|
||||
err := json.Unmarshal([]byte(line), &entry)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to parse log line as json, err: %q, line: %s", err, line)
|
||||
continue
|
||||
}
|
||||
if entry.Level == "" {
|
||||
t.Errorf(`Missing "level" key, line: %s`, line)
|
||||
}
|
||||
if entry.Timestamp == "" {
|
||||
t.Errorf(`Missing "ts" key, line: %s`, line)
|
||||
}
|
||||
if _, err := time.Parse("2006-01-02T15:04:05.000Z0700", entry.Timestamp); entry.Timestamp != "" && err != nil {
|
||||
t.Errorf(`Unexpected "ts" key format, err: %s`, err)
|
||||
}
|
||||
if entry.Caller == "" {
|
||||
t.Errorf(`Missing "caller" key, line: %s`, line)
|
||||
}
|
||||
if entry.Message == "" {
|
||||
t.Errorf(`Missing "message" key, line: %s`, line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type logEntry struct {
|
||||
Level string `json:"level"`
|
||||
Timestamp string `json:"ts"`
|
||||
Caller string `json:"caller"`
|
||||
Message string `json:"msg"`
|
||||
}
|
||||
Reference in New Issue
Block a user