plog

package
Version: v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package plog implements a thin layer over logr to help enforce pinniped's logging convention. Logs are always structured as a constant message with key and value pairs of related metadata.

The logging levels in order of increasing verbosity are: error, warning, info, debug, trace and all.

error and warning logs are always emitted (there is no way for the end user to disable them), and thus should be used sparingly. Ideally, logs at these levels should be actionable.

info should be reserved for "nice to know" information. It should be possible to run a production pinniped server at the info log level with no performance degradation due to high log volume. debug should be used for information targeted at developers and to aid in support cases. Care must be taken at this level to not leak any secrets into the log stream. That is, even though debug may cause performance issues in production, it must not cause security issues in production.

trace should be used to log information related to timing (i.e. the time it took a controller to sync). Just like debug, trace should not leak secrets into the log stream. trace will likely leak information about the current state of the process, but that, along with performance degradation, is expected.

all is reserved for the most verbose and security sensitive information. At this level, full request metadata such as headers and parameters along with the body may be logged. This level is completely unfit for production use both from a performance and security standpoint. Using it is generally an act of desperation to determine why the system is broken.

Index

Constants

View Source
const (
	KlogLevelInfo
	KlogLevelDebug
	KlogLevelTrace
)

Variables

This section is empty.

Functions

func All

func All(msg string, keysAndValues ...interface{})

func Always added in v0.18.0

func Always(msg string, keysAndValues ...interface{})

func Debug

func Debug(msg string, keysAndValues ...interface{})

func DebugErr

func DebugErr(msg string, err error, keysAndValues ...interface{})

func Enabled added in v0.5.0

func Enabled(level LogLevel) bool

Enabled returns whether the provided plog level is enabled, i.e., whether print statements at the provided level will show up.

func Error

func Error(msg string, err error, keysAndValues ...interface{})

func Fatal added in v0.18.0

func Fatal(err error, keysAndValues ...interface{})

func Info

func Info(msg string, keysAndValues ...interface{})

func InfoErr

func InfoErr(msg string, err error, keysAndValues ...interface{})

func Logr deprecated added in v0.18.0

func Logr() logr.Logger

Deprecated: Use New instead. This is meant for old code only. New provides a more ergonomic API and correctly responds to global log config change.

func MaybeSetDeprecatedLogLevel added in v0.18.0

func MaybeSetDeprecatedLogLevel(level *LogLevel, log *LogSpec)

func Setup added in v0.18.0

func Setup() func()

func TestZapOverrides added in v0.18.0

func TestZapOverrides(ctx context.Context, t *testing.T, w io.Writer, f func(*zap.Config), opts ...zap.Option) context.Context

func TestZapr added in v0.18.0

func TestZapr(t *testing.T, w io.Writer) logr.Logger

func Trace

func Trace(msg string, keysAndValues ...interface{})

func TraceErr

func TraceErr(msg string, err error, keysAndValues ...interface{})

func ValidateAndSetLogLevelAndFormatGlobally added in v0.18.0

func ValidateAndSetLogLevelAndFormatGlobally(ctx context.Context, spec LogSpec) error

func Warning

func Warning(msg string, keysAndValues ...interface{})

func WarningErr

func WarningErr(msg string, err error, keysAndValues ...interface{})

func ZapClock added in v0.18.0

func ZapClock(c clock.Clock) zapcore.Clock

Types

type LogFormat added in v0.18.0

type LogFormat string
const (
	FormatJSON LogFormat = "json"
	FormatText LogFormat = "text"
	FormatCLI  LogFormat = "cli" // only used by the pinniped CLI and not the server components

)

func (*LogFormat) UnmarshalJSON added in v0.18.0

func (l *LogFormat) UnmarshalJSON(b []byte) error

type LogLevel

type LogLevel string

LogLevel is an enum that controls verbosity of logs. Valid values in order of increasing verbosity are leaving it unset, info, debug, trace and all.

const (
	// LevelWarning (i.e. leaving the log level unset) maps to klog log level 0.
	LevelWarning LogLevel = ""
	// LevelInfo maps to klog log level 2.
	LevelInfo LogLevel = "info"
	// LevelDebug maps to klog log level 4.
	LevelDebug LogLevel = "debug"
	// LevelTrace maps to klog log level 6.
	LevelTrace LogLevel = "trace"
	// LevelAll maps to klog log level 100 (conceptually it is log level 8).
	LevelAll LogLevel = "all"
)

func (LogLevel) Enabled added in v0.18.0

func (l LogLevel) Enabled(_ zapcore.Level) bool

type LogSpec added in v0.18.0

type LogSpec struct {
	Level  LogLevel  `json:"level,omitempty"`
	Format LogFormat `json:"format,omitempty"`
}

type Logger added in v0.13.0

type Logger interface {
	Error(msg string, err error, keysAndValues ...interface{})
	Warning(msg string, keysAndValues ...interface{})
	WarningErr(msg string, err error, keysAndValues ...interface{})
	Info(msg string, keysAndValues ...interface{})
	InfoErr(msg string, err error, keysAndValues ...interface{})
	Debug(msg string, keysAndValues ...interface{})
	DebugErr(msg string, err error, keysAndValues ...interface{})
	Trace(msg string, keysAndValues ...interface{})
	TraceErr(msg string, err error, keysAndValues ...interface{})
	All(msg string, keysAndValues ...interface{})
	Always(msg string, keysAndValues ...interface{})
	WithValues(keysAndValues ...interface{}) Logger
	WithName(name string) Logger
	// contains filtered or unexported methods
}

Logger implements the plog logging convention described above. The global functions in this package such as Info should be used when one does not intend to write tests assertions for specific log messages. If test assertions are desired, Logger should be passed in as an input. New should be used as the production implementation and TestLogger should be used to write test assertions.

func New added in v0.8.0

func New() Logger

func TestLogger added in v0.18.0

func TestLogger(t *testing.T, w io.Writer) Logger

func WithName added in v0.18.0

func WithName(name string) Logger

func WithValues added in v0.18.0

func WithValues(keysAndValues ...interface{}) Logger

type MinLogger added in v0.18.0

type MinLogger interface {
	Info(msg string, keysAndValues ...interface{})
}

MinLogger is the overlap between Logger and logr.Logger.

Jump to

Keyboard shortcuts

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