log

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: GPL-3.0 Imports: 8 Imported by: 17

Documentation

Index

Constants

View Source
const (
	// CRC16("github.com/privatix/dappctrl/util/log") = 0x6928
	ErrBadLevel errors.Error = 0x6928<<8 + iota
	ErrBadStackLevel
)

Errors.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseConfig

type BaseConfig struct {
	Level      Level
	StackLevel Level
}

BaseConfig is a configuration for LoggerBase.

func NewBaseConfig

func NewBaseConfig() *BaseConfig

NewBaseConfig creates a new LoggerBase configuration.

type FileConfig

type FileConfig struct {
	*WriterConfig
	Filename string
	FileMode os.FileMode
}

FileConfig is a file based logger configuration.

func NewFileConfig

func NewFileConfig() *FileConfig

NewFileConfig creates a new file logger configuration.

type Level

type Level string

Level is a log event severity.

const (
	Debug   Level = "debug"
	Info    Level = "info"
	Warning Level = "warning"
	Error   Level = "error"
	Fatal   Level = "fatal"
)

Log severities.

type Logger

type Logger interface {
	Add(vars ...interface{}) Logger

	Log(lvl Level, msg string)

	Debug(msg string)
	Info(msg string)
	Warn(msg string)
	Error(msg string)
	Fatal(msg string)
}

Logger is an interface for loggers.

func NewFileLogger

func NewFileLogger(conf *FileConfig) (Logger, io.Closer, error)

NewFileLogger creates a new file logger.

func NewMultiLogger

func NewMultiLogger(loggers ...Logger) Logger

NewMultiLogger creates a new multi-logger from given loggers.

func NewStderrLogger

func NewStderrLogger(conf *WriterConfig) (Logger, error)

NewStderrLogger creates a new logger for standard error stream.

func NewTestLogger

func NewTestLogger(conf *WriterConfig, verbose bool) (Logger, error)

NewTestLogger creates a new test logger.

func NewWriterLogger

func NewWriterLogger(conf *WriterConfig, out io.Writer) (Logger, error)

NewWriterLogger creates a new io.Writer based logger.

type LoggerBase

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

LoggerBase is a base logger implementation shared by many other loggers.

func NewLoggerBase

func NewLoggerBase(conf *BaseConfig, log LoggerFunc) (*LoggerBase, error)

NewLoggerBase creates a new LoggerBase.

func (*LoggerBase) Add

func (l *LoggerBase) Add(vars ...interface{}) Logger

Add returns a new logger with added context variables. This function takes alternated key-value pairs (name1, val1, name1, val2, ...). The keys must be strings, but the values can be of any type.

func (*LoggerBase) Debug

func (l *LoggerBase) Debug(msg string)

Debug adds a new debug message.

func (*LoggerBase) Error

func (l *LoggerBase) Error(msg string)

Error adds a new error message.

func (*LoggerBase) Fatal

func (l *LoggerBase) Fatal(msg string)

Fatal adds a new fatal message and then panics.

func (*LoggerBase) Info

func (l *LoggerBase) Info(msg string)

Info adds a new info message.

func (*LoggerBase) Log

func (l *LoggerBase) Log(lvl Level, msg string)

Log adds a new log message with a given severity level.

func (*LoggerBase) Warn

func (l *LoggerBase) Warn(msg string)

Warn adds a new warning message.

type LoggerFunc

type LoggerFunc func(lvl Level, msg string,
	ctx map[string]interface{}, stack *string) error

LoggerFunc is a low-level logging function.

type WriterConfig

type WriterConfig struct {
	*BaseConfig
	Prefix string
	UTC    bool
}

WriterConfig is an io.Writer based logger configuration.

func NewWriterConfig

func NewWriterConfig() *WriterConfig

NewWriterConfig creates a new io.Writer based logger configuration.

Jump to

Keyboard shortcuts

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