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

*: support journald with structured logging zap, rename to "--log-outputs" #9624

Merged
merged 22 commits into from
Apr 25, 2018
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fcbb303
pkg/logutil: add "NewJournaldWriter"
gyuho Apr 24, 2018
1fa80bf
pkg/logutil: add "NewGRPCLoggerV2FromZapCore"
gyuho Apr 24, 2018
48d5542
embed: set journald logging with zap
gyuho Apr 24, 2018
6df3179
pkg/logutil: add "NewRaftLoggerFromZapCore"
gyuho Apr 24, 2018
69c51e2
embed: change "loggerConfig" to "*zap.Config"
gyuho Apr 24, 2018
a34dd27
pkg/logutil: change "NewRaftLogger" function signature
gyuho Apr 24, 2018
d33a74d
embed: add "loggerCore" field for Raft logger
gyuho Apr 24, 2018
3ea7a5d
etcdserver: add "LoggerCore" field for Raft logger
gyuho Apr 24, 2018
f99cb35
embed: rename "LogOutput" to "LogOutputs"
gyuho Apr 25, 2018
d4987f4
CHANGELOG: track logger changes
gyuho Apr 25, 2018
53c5cd5
Documentation/upgrades: highlight "embed.Config.LogOutputs" change
gyuho Apr 25, 2018
a113d6c
functional/rpcpb: change to LogOutputs
gyuho Apr 25, 2018
0e4c94c
CHANGELOG: highlight "--log-outputs" flag
gyuho Apr 25, 2018
22609a6
Documentation/upgrades: highlight "--log-outputs"
gyuho Apr 25, 2018
1539fdd
etcd.conf.yml.sample: rename to "log-outputs"
gyuho Apr 25, 2018
af5bc43
embed,etcdmain: rename to "--log-outputs" flag
gyuho Apr 25, 2018
a6c30ea
functional: rename to "log-outputs"
gyuho Apr 25, 2018
58a6034
*: rename to "--log-outputs" in docs
gyuho Apr 25, 2018
b748abc
*: change typo in "auto-compaction-retention" field
gyuho Apr 25, 2018
88c70d0
embed,integration,snapshot: use "LogOutputs"
gyuho Apr 25, 2018
9cd9ae2
pkg/logutil: do not build journald logger on windows
gyuho Apr 25, 2018
154e2ac
embed: do not import journald dependencies on windows
gyuho Apr 25, 2018
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
Prev Previous commit
Next Next commit
pkg/logutil: add "NewRaftLoggerFromZapCore"
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Apr 25, 2018
commit 6df3179c06b2cd0c17a504dbdf3ff7d32b3b153c
24 changes: 24 additions & 0 deletions pkg/logutil/zap_raft.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
// Copyright 2018 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.

package logutil

import (
"github.com/coreos/etcd/raft"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

// NewRaftLogger converts "*zap.Logger" to "raft.Logger".
@@ -14,6 +30,14 @@ func NewRaftLogger(lcfg zap.Config) (raft.Logger, error) {
return &zapRaftLogger{lg: lg, sugar: lg.Sugar()}, nil
}

// NewRaftLoggerFromZapCore creates "raft.Logger" from "zap.Core"
// and "zapcore.WriteSyncer".
func NewRaftLoggerFromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) raft.Logger {
// "AddCallerSkip" to annotate caller outside of "logutil"
lg := zap.New(cr, zap.AddCaller(), zap.AddCallerSkip(1), zap.ErrorOutput(syncer))
return &zapRaftLogger{lg: lg, sugar: lg.Sugar()}
}

type zapRaftLogger struct {
lg *zap.Logger
sugar *zap.SugaredLogger
19 changes: 19 additions & 0 deletions pkg/logutil/zap_raft_test.go
Original file line number Diff line number Diff line change
@@ -20,10 +20,12 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func TestNewRaftLogger(t *testing.T) {
@@ -68,3 +70,20 @@ func TestNewRaftLogger(t *testing.T) {
t.Fatalf("unexpected caller; %q", string(data))
}
}

func TestNewRaftLoggerFromZapCore(t *testing.T) {
buf := bytes.NewBuffer(nil)
syncer := zapcore.AddSync(buf)
cr := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
syncer,
zap.NewAtomicLevelAt(zap.InfoLevel),
)

lg := NewRaftLoggerFromZapCore(cr, syncer)
lg.Info("TestNewRaftLoggerFromZapCore")
txt := buf.String()
if !strings.Contains(txt, "TestNewRaftLoggerFromZapCore") {
t.Fatalf("unexpected log %q", txt)
}
}