log

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package log implements support for structured logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriterIntoLogger added in v0.2.8

func WriterIntoLogger(l Logger) io.Writer

Types

type Format

type Format uint

Format is a logging format. It implements the pflag.Value interface.

const (
	// FmtLogfmt is the "logfmt" logging format.
	FmtLogfmt Format = iota
	// FmtJSON is the JSON logging format.
	FmtJSON
)

func (*Format) Set

func (f *Format) Set(s string) error

Set sets the Format to the value specified by the provided string.

func (*Format) String

func (f *Format) String() string

String returns the string representation of a Format.

func (*Format) Type

func (f *Format) Type() string

Type returns the list of supported Formats.

type Level

type Level uint

Level is a log level. It implements the pflag.Value interface.

const (
	// LevelDebug is the log level for debug messages.
	LevelDebug Level = iota
	// LevelInfo is the log level for informative messages.
	LevelInfo
	// LevelWarn is the log level for warning messages.
	LevelWarn
	// LevelError is the log level for error messages.
	LevelError
)

func (*Level) Set

func (l *Level) Set(s string) error

Set sets the Level to the value specified by the provided string.

func (*Level) String

func (l *Level) String() string

String returns the string representation of a Level.

func (*Level) Type

func (l *Level) Type() string

Type returns the list of supported Levels.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a structured logger.

func NewDefaultLogger

func NewDefaultLogger(module string) *Logger

NewDefaultLogger initializes a new logger instance with default settings. For usage outside tests, prefer RootLogger() from package `cmd/common`.

func NewLogger

func NewLogger(module string, w io.Writer, format Format, lvl Level) (*Logger, error)

NewLogger initializes a new logger instance.

func (*Logger) Debug

func (l *Logger) Debug(msg string, keyvals ...interface{})

Debug logs the message and key value pairs at the Debug log level.

func (*Logger) Error

func (l *Logger) Error(msg string, keyvals ...interface{})

Error logs the message and key value pairs at the Error log level.

func (*Logger) Info

func (l *Logger) Info(msg string, keyvals ...interface{})

Info logs the message and key value pairs at the Info log level.

func (*Logger) Level

func (l *Logger) Level() Level

Level is the logging level.

func (*Logger) Warn

func (l *Logger) Warn(msg string, keyvals ...interface{})

Warn logs the message and key value pairs at the Warn log level.

func (*Logger) With

func (l *Logger) With(keyvals ...interface{}) *Logger

With returns a clone of the logger with the provided key/value pairs added as context for all subsequent logs.

func (*Logger) WithCallerUnwind added in v0.2.8

func (l *Logger) WithCallerUnwind(n int) *Logger

WithCallerUnwind returns a clone of the logger where the `caller` value will show the n-th entry on the call stack at the time of logging.

func (*Logger) WithModule

func (l *Logger) WithModule(module string) *Logger

WithModule returns a clone of the logger with the provided module added as context for all subsequent logs.

Jump to

Keyboard shortcuts

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