logutil

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package logutil includes utilities to facilitate logging.

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogLevel = "info"
View Source
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.

Functions

func ConvertToZapLevel

func ConvertToZapLevel(lvl string) zapcore.Level

ConvertToZapLevel converts log level string to zapcore.Level.

func MergeOutputPaths

func MergeOutputPaths(cfg zap.Config) zap.Config

MergeOutputPaths merges logging output paths, resolving conflicts.

func NewGRPCLoggerV2

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

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

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: https://github.com/coreos/pkg/blob/master/capnslog/journald_formatter.go

func NewRaftLogger

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

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

func NewRaftLoggerFromZapCore

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

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

func NewRaftLoggerZap

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

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

Types

type Logger

type Logger interface {
	grpclog.LoggerV2

	// 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

func NewDiscardLogger() Logger

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

func NewLogger

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL