logging

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package logging defines the logging API. It used by all plugins, and supports multiple log levels (severities) and various log message formats.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLogger is the default logger
	DefaultLogger Logger

	// DefaultRegistry is the default logging registry
	DefaultRegistry Registry
)
View Source
var (
	Trace  = logLvlFn(TraceLevel)
	Tracef = logfLvlFn(TraceLevel)
	Debug  = logLvlFn(DebugLevel)
	Debugf = logfLvlFn(DebugLevel)
	Info   = logLvlFn(InfoLevel)
	Infof  = logfLvlFn(InfoLevel)
	Warn   = logLvlFn(WarnLevel)
	Warnf  = logfLvlFn(WarnLevel)
	Error  = logLvlFn(ErrorLevel)
	Errorf = logfLvlFn(ErrorLevel)
	Fatal  = log.Fatal
	Fatalf = log.Fatalf
	Panic  = log.Panic
	Panicf = log.Panicf
)

Functions

This section is empty.

Types

type Fields

type Fields map[string]interface{}

Fields is a type accepted by WithFields method.

type LogLevel

type LogLevel uint32

LogLevel defines severity of log entry.

const (
	// PanicLevel - highest level of severity. Logs and then calls panic with the message passed in.
	PanicLevel LogLevel = iota
	// FatalLevel - logs and then calls `os.Exit(1)`.
	FatalLevel
	// ErrorLevel - used for errors that should definitely be noted.
	ErrorLevel
	// WarnLevel - non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel - general operational entries about what's going on inside the application.
	InfoLevel
	// DebugLevel - enabled for debugging, very verbose logging.
	DebugLevel
	// TraceLevel - extra level for debugging specific parts.
	TraceLevel
)

func ParseLogLevel

func ParseLogLevel(level string) (LogLevel, error)

ParseLogLevel parses the string as log level.

func (LogLevel) MarshalText

func (level LogLevel) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (LogLevel) String

func (level LogLevel) String() string

Convert the LogLevel to a string.

func (*LogLevel) UnmarshalText

func (level *LogLevel) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type LogWithLevel

type LogWithLevel interface {
	WithField(key string, value interface{}) LogWithLevel
	WithFields(fields Fields) LogWithLevel
	WithError(err error) LogWithLevel

	Tracef(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})
	Printf(format string, args ...interface{})

	Trace(args ...interface{})
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})
	Print(args ...interface{})

	Traceln(args ...interface{})
	Debugln(args ...interface{})
	Infoln(args ...interface{})
	Println(args ...interface{})
	Warnln(args ...interface{})
	Warningln(args ...interface{})
	Errorln(args ...interface{})
	Fatalln(args ...interface{})
	Panicln(args ...interface{})
}

LogWithLevel allows to log with different log levels

type Logger

type Logger interface {
	LogWithLevel

	// GetName returns the logger name
	GetName() string
	// SetLevel modifies the log level
	SetLevel(level LogLevel)
	// GetLevel returns currently set log level
	GetLevel() LogLevel
	// AddHook adds hook to logger
	AddHook(hook logrus.Hook)
	// SetOutput sets output writer
	SetOutput(out io.Writer)
	// SetFormatter sets custom formatter
	SetFormatter(formatter logrus.Formatter)
}

Logger provides logging capabilities

type LoggerFactory

type LoggerFactory interface {
	NewLogger(name string) Logger
}

LoggerFactory is API for the plugins that want to create their own loggers.

type ParentLogger

type ParentLogger struct {
	Logger
	Prefix  string
	Factory LoggerFactory
}

ParentLogger provides logger with logger factory that creates loggers with prefix.

func NewParentLogger

func NewParentLogger(name string, factory LoggerFactory) *ParentLogger

NewParentLogger creates new parent logger with given LoggerFactory and name as prefix.

func (*ParentLogger) NewLogger

func (p *ParentLogger) NewLogger(name string) Logger

NewLogger returns logger using name prefixed with prefix defined in parent logger. If Factory is nil, DefaultRegistry is used.

type PluginLogger

type PluginLogger interface {
	Logger
	LoggerFactory
}

PluginLogger is intended for: 1. small plugins (that just need one logger; name corresponds to plugin name) 2. large plugins that need multiple loggers (all loggers share same name prefix)

func ForPlugin

func ForPlugin(name string) PluginLogger

ForPlugin is used to initialize plugin logger by name and optionally created children (their name prefixed by plugin logger name)

type Registry

type Registry interface {
	LoggerFactory

	// ListLoggers returns a map (loggerName => log level)
	ListLoggers() map[string]string
	// SetLevel modifies log level of selected logger in the registry
	SetLevel(logger, level string) error
	// GetLevel returns the currently set log level of the logger from registry
	GetLevel(logger string) (string, error)
	// Lookup returns a logger instance identified by name from registry
	Lookup(loggerName string) (logger Logger, found bool)
	// ClearRegistry removes all loggers except the default one from registry
	ClearRegistry()
	// AddHook stores hooks from log manager to be used for new loggers
	AddHook(hook logrus.Hook)
}

Registry groups multiple Logger instances and allows to mange their log levels.

Directories

Path Synopsis
Package logmanager implements the log manager that allows users to set log levels at run-time via a REST API.
Package logmanager implements the log manager that allows users to set log levels at run-time via a REST API.
Package logrus implements the logging API based on the Logrus logger.
Package logrus implements the logging API based on the Logrus logger.

Jump to

Keyboard shortcuts

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