logging

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: Apache-2.0 Imports: 12 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLevel

func SetLevel(level Level)

SetLevel sets the root logger level

Types

type Config

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

Config logging configuration

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 Field

type Field interface {
	// contains filtered or unexported methods
}

Field is a structured logger field

func Bool

func Bool(name string, value bool) Field

Bool creates a named bool field

func Boolp

func Boolp(name string, value *bool) Field

Boolp creates a named bool pointer field

func Bools

func Bools(name string, value []bool) Field

Bools creates a named bool slice field

func Byte

func Byte(name string, value byte) Field

Byte creates a named byte field

func ByteString

func ByteString(name string, value []byte) Field

ByteString creates a named byte string field

func ByteStrings

func ByteStrings(name string, value [][]byte) Field

ByteStrings creates a named byte string slice field

func Bytes

func Bytes(name string, value []byte) Field

Bytes creates a named byte slice field

func Complex128

func Complex128(name string, value complex128) Field

Complex128 creates a named complex128 field

func Complex128p

func Complex128p(name string, value *complex128) Field

Complex128p creates a named complex128 pointer field

func Complex128s

func Complex128s(name string, value []complex128) Field

Complex128s creates a named complex128 slice field

func Complex64

func Complex64(name string, value complex64) Field

Complex64 creates a named complex64 field

func Complex64p

func Complex64p(name string, value *complex64) Field

Complex64p creates a named complex64 pointer field

func Complex64s

func Complex64s(name string, value []complex64) Field

Complex64s creates a named complex64 slice field

func Duration

func Duration(name string, value time.Duration) Field

Duration creates a named Duration field

func Durationp

func Durationp(name string, value *time.Duration) Field

Durationp creates a named Duration pointer field

func Durations

func Durations(name string, value []time.Duration) Field

Durations creates a named Duration slice field

func Float32

func Float32(name string, value float32) Field

Float32 creates a named float32 field

func Float32p

func Float32p(name string, value *float32) Field

Float32p creates a named float32 pointer field

func Float32s

func Float32s(name string, value []float32) Field

Float32s creates a named float32 slice field

func Float64

func Float64(name string, value float64) Field

Float64 creates a named float64 field

func Float64p

func Float64p(name string, value *float64) Field

Float64p creates a named float64 pointer field

func Float64s

func Float64s(name string, value []float64) Field

Float64s creates a named float64 slice field

func Int

func Int(name string, value int) Field

Int creates a named int field

func Int32

func Int32(name string, value int32) Field

Int32 creates a named int32 field

func Int32p

func Int32p(name string, value *int32) Field

Int32p creates a named int32 pointer field

func Int32s

func Int32s(name string, value []int32) Field

Int32s creates a named int32 slice field

func Int64

func Int64(name string, value int64) Field

Int64 creates a named int64 field

func Int64p

func Int64p(name string, value *int64) Field

Int64p creates a named int64 pointer field

func Int64s

func Int64s(name string, value []int64) Field

Int64s creates a named int64 slice field

func Intp

func Intp(name string, value *int) Field

Intp creates a named int pointer field

func Ints

func Ints(name string, value []int) Field

Ints creates a named int slice field

func String

func String(name string, value string) Field

String creates a named string field

func Stringp

func Stringp(name string, value *string) Field

Stringp creates a named string pointer field

func Strings

func Strings(name string, value []string) Field

Strings creates a named string slice field

func Time

func Time(name string, value time.Time) Field

Time creates a named Time field

func Timep

func Timep(name string, value *time.Time) Field

Timep creates a named Time pointer field

func Times

func Times(name string, value []time.Time) Field

Times creates a named Time slice field

func Uint

func Uint(name string, value uint) Field

Uint creates a named uint field

func Uint32

func Uint32(name string, value uint32) Field

Uint32 creates a named uint32 field

func Uint32p

func Uint32p(name string, value *uint32) Field

Uint32p creates a named uint32 pointer field

func Uint32s

func Uint32s(name string, value []uint32) Field

Uint32s creates a named uint32 slice field

func Uint64

func Uint64(name string, value uint64) Field

Uint64 creates a named uint64 field

func Uint64p

func Uint64p(name string, value *uint64) Field

Uint64p creates a named uint64 pointer field

func Uint64s

func Uint64s(name string, value []uint64) Field

Uint64s creates a named uint64 slice field

func Uintp

func Uintp(name string, value *uint) Field

Uintp creates a named uint pointer field

func Uints

func Uints(name string, value []uint) Field

Uints creates a named uint slice field

type FileSinkConfig

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

FileSinkConfig is the configuration for a file sink

type KafkaSinkConfig

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

KafkaSinkConfig is the configuration for a Kafka sink

type Level

type Level int32

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

	// EmptyLevel :
	EmptyLevel
)

func (Level) String

func (l Level) String() string

String :

type Logger

type Logger interface {
	// Name returns the logger name
	Name() string

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

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

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

	// WithFields adds fields to the logger
	WithFields(fields ...Field) Logger

	// Sync flushes the logger
	Sync() error

	Debug(...interface{})
	Debugf(template string, args ...interface{})
	Debugw(msg string, fields ...Field)

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

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

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

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

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

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

Logger represents an abstract logging interface.

func GetLogger

func GetLogger(names ...string) Logger

GetLogger gets a logger by name

type LoggerConfig

type LoggerConfig struct {
	Name   string                  `yaml:"name"`
	Level  *string                 `yaml:"level,omitempty"`
	Output map[string]OutputConfig `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 Output

type Output interface {
	WithFields(fields ...Field) Output
	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Error(msg string, fields ...Field)
	Fatal(msg string, fields ...Field)
	Panic(msg string, fields ...Field)
	DPanic(msg string, fields ...Field)
	Warn(msg string, fields ...Field)
	Sync() error
}

Output is a logging output

type OutputConfig

type OutputConfig struct {
	Name  string  `yaml:"name"`
	Sink  *string `yaml:"sink"`
	Level *string `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            `yaml:"name"`
	Type     *SinkType         `yaml:"type,omitempty"`
	Encoding *SinkEncoding     `yaml:"encoding,omitempty"`
	Stdout   *StdoutSinkConfig `yaml:"stdout,omitempty"`
	Stderr   *StderrSinkConfig `yaml:"stderr,omitempty"`
	File     *FileSinkConfig   `yaml:"file,omitempty"`
	Kafka    *KafkaSinkConfig  `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

Jump to

Keyboard shortcuts

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