logging

package
v0.0.0-...-8fa78e2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LevelStrings = LevelStringsType{
	DebugLevel:  "DEBUG",
	InfoLevel:   "INFO",
	WarnLevel:   "WARN",
	ErrorLevel:  "ERROR",
	FatalLevel:  "FATAL",
	PanicLevel:  "PANIC",
	DPanicLevel: "DPANIC",
}

Functions

func Configure

func Configure(config *Config) error

configure configures the loggers

func Register

func Register(domain string, fn registerFunc)

Register the logging domain with a reregister callback that will be called when the logging configuration changes. The given callback will be called directly from this function with a current Logger based on the current configuration.

func SetLevel

func SetLevel(level Level)

SetLevel sets the root logger level

Types

type Config

type Config struct {
	Loggers map[string]LoggerConfig `json:"loggers" yaml:"loggers"`
	Sinks   map[string]SinkConfig   `json:"sinks" yaml:"sinks"`
}

Config logging configuration

func (*Config) Apply

func (c *Config) Apply() error

Process everything in this config structure

func (Config) GetLogger

func (c Config) GetLogger(name string) (LoggerConfig, bool)

GetLogger returns a logger by name

func (Config) GetLoggers

func (c Config) GetLoggers() []LoggerConfig

GetLoggers returns the configured loggers

func (Config) GetRootLogger

func (c Config) GetRootLogger() LoggerConfig

GetRootLogger returns the root logger configuration

func (Config) GetSink

func (c Config) GetSink(name string) (SinkConfig, bool)

GetSink returns a sink by name

func (Config) GetSinks

func (c Config) GetSinks() []SinkConfig

GetSinks returns the configured sinks

type FileSinkConfig

type FileSinkConfig struct {
	Path string `json:"path" yaml:"path"`
}

FileSinkConfig is the configuration for a file sink

type KafkaSinkConfig

type KafkaSinkConfig struct {
	Topic   string   `json:"topic" yaml:"topic"`
	Key     string   `json:"key" yaml:"key"`
	Brokers []string `json:"brokers" yaml:"brokers"`
}

KafkaSinkConfig is the configuration for a Kafka sink

type Level

type Level int

Level :

const (
	// DebugLevel logs a message at debug level
	DebugLevel Level = iota
	// InfoLevel logs a message at info level
	InfoLevel
	// WarnLevel logs a message at warning level
	WarnLevel
	// ErrorLevel logs a message at error level
	ErrorLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// DPanicLevel logs at PanicLevel; otherwise, it logs at ErrorLevel
	DPanicLevel
	// Last level in the list
	LastLevel

	// EmptyLevel :
	EmptyLevel = InfoLevel
)

func LevelString2Level

func LevelString2Level(l string) Level

func (Level) String

func (l Level) String() string

String :

type LevelStringsType

type LevelStringsType []string

func (LevelStringsType) String

func (ls LevelStringsType) String() string

type Logger

type Logger interface {
	Output

	// Name returns the logger name
	Name() string

	// GetLogger gets a descendant of this Logger
	GetLogger(names ...string) Logger

	// GetLevel returns the logger's level
	GetLevel() Level

	// SetLevel sets the logger's level
	SetLevel(level Level)
}

Logger represents an abstract logging interface.

func GetLogger

func GetLogger(names ...string) Logger

GetLogger gets a logger by name. If no name is provided, the caller's package name will be used if available. If a single name is provided, the ancestry will be determined by splitting the string on backslashes. If multiple names are provided, the set of names defines the logger ancestry.

type LoggerConfig

type LoggerConfig struct {
	Name   string                  `json:"name" yaml:"name"`
	Level  *string                 `json:"level" yaml:"level,omitempty"`
	Output map[string]OutputConfig `json:"output" yaml:"output"`
}

LoggerConfig is the configuration for a logger

func (LoggerConfig) GetLevel

func (c LoggerConfig) GetLevel() Level

GetLevel returns the logger level

func (LoggerConfig) GetOutput

func (c LoggerConfig) GetOutput(name string) (OutputConfig, bool)

GetOutput returns an output by name

func (LoggerConfig) GetOutputs

func (c LoggerConfig) GetOutputs() []OutputConfig

GetOutputs returns the logger outputs

type LoggerData

type LoggerData struct {
	Level string
}

type LoggerDataList

type LoggerDataList map[string]*LoggerData

func GetLoggerDataList

func GetLoggerDataList() LoggerDataList

GetLoggerList returns the configured logger domains including operational configuration

type Output

type Output interface {
	Debug(...interface{})
	Debugf(template string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})

	Info(...interface{})
	Infof(template string, args ...interface{})
	Infow(msg string, keysAndValues ...interface{})

	Error(...interface{})
	Errorf(template string, args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})

	Fatal(...interface{})
	Fatalf(template string, args ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	Panic(...interface{})
	Panicf(template string, args ...interface{})
	Panicw(msg string, keysAndValues ...interface{})

	DPanic(...interface{})
	DPanicf(template string, args ...interface{})
	DPanicw(msg string, keysAndValues ...interface{})

	Warn(...interface{})
	Warnf(template string, args ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
}

Output is a logging output

type OutputConfig

type OutputConfig struct {
	Name  string  `json:"name" yaml:"name"`
	Sink  *string `json:"sink" yaml:"sink"`
	Level *string `json:"level" yaml:"level,omitempty"`
}

OutputConfig is the configuration for a sink output

func (OutputConfig) GetLevel

func (c OutputConfig) GetLevel() Level

GetLevel returns the output level

func (OutputConfig) GetSink

func (c OutputConfig) GetSink() string

GetSink returns the output sink

type SinkConfig

type SinkConfig struct {
	Name     string            `json:"name" yaml:"name"`
	Type     *SinkType         `json:"type" yaml:"type,omitempty"`
	Encoding *SinkEncoding     `json:"encoding" yaml:"encoding,omitempty"`
	Stdout   *StdoutSinkConfig `json:"stdout" yaml:"stdout,omitempty"`
	Stderr   *StderrSinkConfig `json:"stderr" yaml:"stderr,omitempty"`
	File     *FileSinkConfig   `json:"file" yaml:"file,omitempty"`
	Kafka    *KafkaSinkConfig  `json:"kafka" yaml:"kafka,omitempty"`
}

SinkConfig is the configuration for a sink

func (SinkConfig) GetEncoding

func (c SinkConfig) GetEncoding() SinkEncoding

GetEncoding returns the sink encoding

func (SinkConfig) GetFileSinkConfig

func (c SinkConfig) GetFileSinkConfig() FileSinkConfig

GetFileSinkConfig returns the file sink configuration

func (SinkConfig) GetKafkaSinkConfig

func (c SinkConfig) GetKafkaSinkConfig() KafkaSinkConfig

GetKafkaSinkConfig returns the Kafka sink configuration

func (SinkConfig) GetStderrSinkConfig

func (c SinkConfig) GetStderrSinkConfig() StderrSinkConfig

GetStderrSinkConfig returns the stderr sink configuration

func (SinkConfig) GetStdoutSinkConfig

func (c SinkConfig) GetStdoutSinkConfig() StdoutSinkConfig

GetStdoutSinkConfig returns the stdout sink configuration

func (SinkConfig) GetType

func (c SinkConfig) GetType() SinkType

GetType returns the sink type

type SinkEncoding

type SinkEncoding string

SinkEncoding is the encoding for a sink

const (
	// ConsoleEncoding is an encoding for outputs to the console
	ConsoleEncoding SinkEncoding = "console"
	// JSONEncoding is an encoding for JSON outputs
	JSONEncoding SinkEncoding = "json"
)

func (SinkEncoding) String

func (e SinkEncoding) String() string

type SinkType

type SinkType string

SinkType is the type of a sink

const (
	// StdoutSinkType is the sink type for stdout
	StdoutSinkType SinkType = "stdout"
	// StderrSinkType is the sink type for stderr
	StderrSinkType SinkType = "stderr"
	// FileSinkType is the type for a file sink
	FileSinkType SinkType = "file"
	// KafkaSinkType is the sink type for the Kafka sink
	KafkaSinkType SinkType = "kafka"
)

func (SinkType) String

func (t SinkType) String() string

type StderrSinkConfig

type StderrSinkConfig struct {
}

StderrSinkConfig is the configuration for an stderr sink

type StdoutSinkConfig

type StdoutSinkConfig struct {
}

StdoutSinkConfig is the configuration for an stdout sink

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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