etcd: Index | Files

package logutil

import ""

Package logutil includes utilities to facilitate logging.


Package Files

discard_logger.go doc.go log_level.go logger.go merge_logger.go package_logger.go zap.go zap_grpc.go zap_journal.go zap_raft.go


var DefaultLogLevel = "info"
var DefaultZapLoggerConfig = zap.Config{
    Level: zap.NewAtomicLevelAt(ConvertToZapLevel(DefaultLogLevel)),

    Development: false,
    Sampling: &zap.SamplingConfig{
        Initial:    100,
        Thereafter: 100,

    Encoding: "json",

    EncoderConfig: zapcore.EncoderConfig{
        TimeKey:        "ts",
        LevelKey:       "level",
        NameKey:        "logger",
        CallerKey:      "caller",
        MessageKey:     "msg",
        StacktraceKey:  "stacktrace",
        LineEnding:     zapcore.DefaultLineEnding,
        EncodeLevel:    zapcore.LowercaseLevelEncoder,
        EncodeTime:     zapcore.ISO8601TimeEncoder,
        EncodeDuration: zapcore.StringDurationEncoder,
        EncodeCaller:   zapcore.ShortCallerEncoder,

    OutputPaths:      []string{"stderr"},
    ErrorOutputPaths: []string{"stderr"},

DefaultZapLoggerConfig defines default zap logger configuration.

func ConvertToCapnslogLogLevel Uses

func ConvertToCapnslogLogLevel(lvl string) capnslog.LogLevel

ConvertToCapnslogLogLevel convert log level string to capnslog.LogLevel. TODO: deprecate this in 3.5

func ConvertToZapLevel Uses

func ConvertToZapLevel(lvl string) zapcore.Level

ConvertToZapLevel converts log level string to zapcore.Level.

func MergeOutputPaths Uses

func MergeOutputPaths(cfg zap.Config) zap.Config

MergeOutputPaths merges logging output paths, resolving conflicts.

func NewGRPCLoggerV2 Uses

func NewGRPCLoggerV2(lcfg zap.Config) (grpclog.LoggerV2, error)

NewGRPCLoggerV2 converts "*zap.Logger" to "grpclog.LoggerV2". It discards all INFO level logging in gRPC, if debug level is not enabled in "*zap.Logger".

func NewGRPCLoggerV2FromZapCore Uses

func NewGRPCLoggerV2FromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) grpclog.LoggerV2

NewGRPCLoggerV2FromZapCore creates "grpclog.LoggerV2" from "zap.Core" and "zapcore.WriteSyncer". It discards all INFO level logging in gRPC, if debug level is not enabled in "*zap.Logger".

func NewJournalWriter Uses

func NewJournalWriter(wr io.Writer) (io.Writer, error)

NewJournalWriter wraps "io.Writer" to redirect log output to the local systemd journal. If journald send fails, it fails back to writing to the original writer. The decode overhead is only <30µs per write. Reference:

func NewRaftLogger Uses

func NewRaftLogger(lcfg *zap.Config) (raft.Logger, error)

NewRaftLogger builds "raft.Logger" from "*zap.Config".

func NewRaftLoggerFromZapCore Uses

func NewRaftLoggerFromZapCore(cr zapcore.Core, syncer zapcore.WriteSyncer) raft.Logger

NewRaftLoggerFromZapCore creates "raft.Logger" from "zap.Core" and "zapcore.WriteSyncer".

func NewRaftLoggerZap Uses

func NewRaftLoggerZap(lg *zap.Logger) raft.Logger

NewRaftLoggerZap converts "*zap.Logger" to "raft.Logger".

type Logger Uses

type Logger interface {

    // Lvl returns logger if logger's verbosity level >= "lvl".
    // Otherwise, logger that discards everything.
    Lvl(lvl int) grpclog.LoggerV2

Logger defines logging interface. TODO: deprecate in v3.5.

func NewDiscardLogger Uses

func NewDiscardLogger() Logger

NewDiscardLogger returns a new Logger that discards everything except "fatal".

func NewLogger Uses

func NewLogger(g grpclog.LoggerV2) Logger

NewLogger wraps "grpclog.LoggerV2" that implements "Logger" interface.

For example:

var defaultLogger Logger
g := grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4)
defaultLogger = NewLogger(g)

func NewPackageLogger Uses

func NewPackageLogger(repo, pkg string) Logger

NewPackageLogger wraps "*capnslog.PackageLogger" that implements "Logger" interface.

For example:

var defaultLogger Logger
defaultLogger = NewPackageLogger("", "snapshot")

type MergeLogger Uses

type MergeLogger struct {
    // contains filtered or unexported fields

MergeLogger supports merge logging, which merges repeated log lines and prints summary log lines instead.

For merge logging, MergeLogger prints out the line when the line appears at the first time. MergeLogger holds the same log line printed within defaultMergePeriod, and prints out summary log line at the end of defaultMergePeriod. It stops merging when the line doesn't appear within the defaultMergePeriod.

func NewMergeLogger Uses

func NewMergeLogger(logger *capnslog.PackageLogger) *MergeLogger

func (*MergeLogger) MergeError Uses

func (l *MergeLogger) MergeError(entries ...interface{})

func (*MergeLogger) MergeErrorf Uses

func (l *MergeLogger) MergeErrorf(format string, args ...interface{})

func (*MergeLogger) MergeInfo Uses

func (l *MergeLogger) MergeInfo(entries ...interface{})

func (*MergeLogger) MergeInfof Uses

func (l *MergeLogger) MergeInfof(format string, args ...interface{})

func (*MergeLogger) MergeNotice Uses

func (l *MergeLogger) MergeNotice(entries ...interface{})

func (*MergeLogger) MergeNoticef Uses

func (l *MergeLogger) MergeNoticef(format string, args ...interface{})

func (*MergeLogger) MergeWarning Uses

func (l *MergeLogger) MergeWarning(entries ...interface{})

func (*MergeLogger) MergeWarningf Uses

func (l *MergeLogger) MergeWarningf(format string, args ...interface{})

Package logutil imports 18 packages (graph) and is imported by 182 packages. Updated 2019-12-05. Refresh now. Tools for package owners.