package logutil

import "go.etcd.io/etcd/client/pkg/v3/logutil"

Package logutil includes utilities to facilitate logging.

Index

Constants

const (
	JSONLogFormat    = "json"
	ConsoleLogFormat = "console"
	//revive:disable:var-naming
	// Deprecated: Please use JSONLogFormat.
	JsonLogFormat = JSONLogFormat
)

Variables

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

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

	Encoding: DefaultLogFormat,

	EncoderConfig: zapcore.EncoderConfig{
		TimeKey:       "ts",
		LevelKey:      "level",
		NameKey:       "logger",
		CallerKey:     "caller",
		MessageKey:    "msg",
		StacktraceKey: "stacktrace",
		LineEnding:    zapcore.DefaultLineEnding,
		EncodeLevel:   zapcore.LowercaseLevelEncoder,

		EncodeTime: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
			enc.AppendString(t.Format("2006-01-02T15:04:05.000000Z0700"))
		},

		EncodeDuration: zapcore.StringDurationEncoder,
		EncodeCaller:   zapcore.ShortCallerEncoder,
	},

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

DefaultZapLoggerConfig defines default zap logger configuration.

Functions

func ConvertToZapFormat

func ConvertToZapFormat(format string) (string, error)

ConvertToZapFormat converts and validated log format string.

func ConvertToZapLevel

func ConvertToZapLevel(lvl string) zapcore.Level

ConvertToZapLevel converts log level string to zapcore.Level.

func CreateDefaultZapLogger

func CreateDefaultZapLogger(level zapcore.Level) (*zap.Logger, error)

CreateDefaultZapLogger creates a logger with default zap configuration

func MergeOutputPaths

func MergeOutputPaths(cfg zap.Config) zap.Config

MergeOutputPaths merges logging output paths, resolving conflicts.

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

Source Files

doc.go log_format.go log_level.go zap.go zap_journal.go

Version
v3.6.0 (latest)
Published
May 15, 2025
Platform
js/wasm
Imports
12 packages
Last checked
now

Tools for package owners.