logger

package
v1.9.0-RC2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultTimeFormat is the time format to use for JSON output
	DefaultTimeFormat = "2006-01-02T15:04:05.000000Z07:00"

	// LogFormatText is the log format to use for TEXT output
	LogFormatText = "text"

	// LogFormatJSON is the log format to use for JSON output
	LogFormatJSON = "json"
)

Variables

View Source
var (
	ErrInvalidLoggerType = errors.New("invalid logger type")
)

Functions

This section is empty.

Types

type FileLogger

type FileLogger struct {
	Logger   *log.Logger
	LogLevel LogLevel
	// contains filtered or unexported fields
}

FileLogger ...

func (*FileLogger) Close

func (l *FileLogger) Close() error

Close the logger ...

func (*FileLogger) Debugf

func (l *FileLogger) Debugf(f string, v ...interface{})

Debugf ...

func (*FileLogger) Errorf

func (l *FileLogger) Errorf(f string, v ...interface{})

Errorf ...

func (*FileLogger) Infof

func (l *FileLogger) Infof(f string, v ...interface{})

Infof ...

func (*FileLogger) Warningf

func (l *FileLogger) Warningf(f string, v ...interface{})

Warningf ...

type JsonLogger

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

JsonLogger is a logger implementation for json logging.

func NewJSONLogger

func NewJSONLogger(opts *Options) (*JsonLogger, error)

NewJSONLogger returns a json logger.

func (*JsonLogger) Close

func (i *JsonLogger) Close() error

Close the logger

func (*JsonLogger) Debug

func (l *JsonLogger) Debug(msg string, args ...interface{})

Debugf prints the message and args at DEBUG level

func (*JsonLogger) Debugf

func (l *JsonLogger) Debugf(msg string, args ...interface{})

Debugf prints the message and args at DEBUG level

func (*JsonLogger) Error

func (l *JsonLogger) Error(msg string, args ...interface{})

Errorf prints the message and args at ERROR level

func (*JsonLogger) Errorf

func (l *JsonLogger) Errorf(msg string, args ...interface{})

Errorf prints the message and args at ERROR level

func (*JsonLogger) Info

func (l *JsonLogger) Info(msg string, args ...interface{})

Infof prints the message and args at INFO level

func (*JsonLogger) Infof

func (l *JsonLogger) Infof(msg string, args ...interface{})

Infof prints the message and args at INFO level

func (*JsonLogger) Name

func (i *JsonLogger) Name() string

Name returns the loggers name

func (*JsonLogger) SetLogLevel

func (l *JsonLogger) SetLogLevel(level LogLevel)

Update the logging level

func (*JsonLogger) Warning

func (l *JsonLogger) Warning(msg string, args ...interface{})

Warningf prints the message and args at WARN level

func (*JsonLogger) Warningf

func (l *JsonLogger) Warningf(msg string, args ...interface{})

Warningf prints the message and args at WARN level

type LogLevel

type LogLevel int8

LogLevel ...

const (
	LogDebug LogLevel = iota
	LogInfo
	LogWarn
	LogError
)

Log levels

func LogLevelFromEnvironment

func LogLevelFromEnvironment() LogLevel

type Logger

type Logger interface {
	Errorf(string, ...interface{})
	Warningf(string, ...interface{})
	Infof(string, ...interface{})
	Debugf(string, ...interface{})
	Close() error
}

Logger ...

func NewFileLogger

func NewFileLogger(name string, file string) (logger Logger, out *os.File, err error)

NewFileLogger ...

func NewFileLoggerWithLevel

func NewFileLoggerWithLevel(name string, file string, level LogLevel) (logger Logger, err error)

NewFileLoggerWithLevel ...

func NewLogger

func NewLogger(opts *Options) (logger Logger, err error)

NewLogger is a factory for selecting a logger based on options

func NewSimpleLogger

func NewSimpleLogger(name string, out io.Writer) Logger

NewSimpleLogger ...

func NewSimpleLoggerWithLevel

func NewSimpleLoggerWithLevel(name string, out io.Writer, level LogLevel) Logger

NewSimpleLoggerWithLevel ...

type MemoryLogger

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

func NewMemoryLogger

func NewMemoryLogger() *MemoryLogger

func NewMemoryLoggerWithLevel

func NewMemoryLoggerWithLevel(level LogLevel) *MemoryLogger

func (*MemoryLogger) Close

func (l *MemoryLogger) Close() error

Close the logger ...

func (*MemoryLogger) Debugf

func (l *MemoryLogger) Debugf(fmt string, args ...interface{})

func (*MemoryLogger) Errorf

func (l *MemoryLogger) Errorf(fmt string, args ...interface{})

func (*MemoryLogger) GetLogs

func (l *MemoryLogger) GetLogs() []string

func (*MemoryLogger) Infof

func (l *MemoryLogger) Infof(fmt string, args ...interface{})

func (*MemoryLogger) Warningf

func (l *MemoryLogger) Warningf(fmt string, args ...interface{})

type Options

type Options struct {
	// Name of the subsystem to prefix logs with
	Name string

	// The threshold for the logger. Anything less severe is supressed
	Level LogLevel

	// Where to write the logs to. Defaults to os.Stderr if nil
	Output io.Writer

	// The time format to use instead of the default
	TimeFormat string

	// A function which is called to get the time object that is formatted using `TimeFormat`
	TimeFnc TimeFunc

	// The format in which logs will be formatted. (eg: text/json)
	LogFormat string

	// The file to write to.
	LogFile string
}

Options can be used to configure a new logger.

type SimpleLogger

type SimpleLogger struct {
	Logger   *log.Logger
	LogLevel LogLevel
}

SimpleLogger ...

func (*SimpleLogger) Close

func (l *SimpleLogger) Close() error

Close the logger ...

func (*SimpleLogger) Debugf

func (l *SimpleLogger) Debugf(f string, v ...interface{})

Debugf ...

func (*SimpleLogger) Errorf

func (l *SimpleLogger) Errorf(f string, v ...interface{})

Errorf ...

func (*SimpleLogger) Infof

func (l *SimpleLogger) Infof(f string, v ...interface{})

Infof ...

func (*SimpleLogger) Warningf

func (l *SimpleLogger) Warningf(f string, v ...interface{})

Warningf ...

type TimeFunc

type TimeFunc = func() time.Time

Jump to

Keyboard shortcuts

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