logger

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

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 added in v0.7.0

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

FileLogger ...

func (*FileLogger) Close added in v1.3.2

func (l *FileLogger) Close() error

Close the logger ...

func (*FileLogger) Debugf added in v0.7.0

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

Debugf ...

func (*FileLogger) Errorf added in v0.7.0

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

Errorf ...

func (*FileLogger) Infof added in v0.7.0

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

Infof ...

func (*FileLogger) Warningf added in v0.7.0

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

Warningf ...

type JsonLogger added in v1.3.2

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

JsonLogger is a logger implementation for json logging.

func NewJSONLogger added in v1.3.2

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

NewJSONLogger returns a json logger.

func (*JsonLogger) Close added in v1.3.2

func (i *JsonLogger) Close() error

Close the logger

func (*JsonLogger) Debug added in v1.3.2

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

Debugf prints the message and args at DEBUG level

func (*JsonLogger) Debugf added in v1.3.2

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

Debugf prints the message and args at DEBUG level

func (*JsonLogger) Error added in v1.3.2

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

Errorf prints the message and args at ERROR level

func (*JsonLogger) Errorf added in v1.3.2

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

Errorf prints the message and args at ERROR level

func (*JsonLogger) Info added in v1.3.2

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

Infof prints the message and args at INFO level

func (*JsonLogger) Infof added in v1.3.2

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

Infof prints the message and args at INFO level

func (*JsonLogger) Name added in v1.3.2

func (i *JsonLogger) Name() string

Name returns the loggers name

func (*JsonLogger) SetLogLevel added in v1.3.2

func (l *JsonLogger) SetLogLevel(level LogLevel)

Update the logging level

func (*JsonLogger) Warning added in v1.3.2

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

Warningf prints the message and args at WARN level

func (*JsonLogger) Warningf added in v1.3.2

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 added in v1.3.2

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 added in v1.3.2

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 added in v1.3.2

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

func NewMemoryLogger added in v1.3.2

func NewMemoryLogger() *MemoryLogger

func NewMemoryLoggerWithLevel added in v1.3.2

func NewMemoryLoggerWithLevel(level LogLevel) *MemoryLogger

func (*MemoryLogger) Close added in v1.3.2

func (l *MemoryLogger) Close() error

Close the logger ...

func (*MemoryLogger) Debugf added in v1.3.2

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

func (*MemoryLogger) Errorf added in v1.3.2

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

func (*MemoryLogger) GetLogs added in v1.3.2

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

func (*MemoryLogger) Infof added in v1.3.2

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

func (*MemoryLogger) Warningf added in v1.3.2

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

type Options added in v1.3.2

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 added in v0.7.0

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

SimpleLogger ...

func (*SimpleLogger) Close added in v1.3.2

func (l *SimpleLogger) Close() error

Close the logger ...

func (*SimpleLogger) Debugf added in v0.7.0

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

Debugf ...

func (*SimpleLogger) Errorf added in v0.7.0

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

Errorf ...

func (*SimpleLogger) Infof added in v0.7.0

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

Infof ...

func (*SimpleLogger) Warningf added in v0.7.0

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

Warningf ...

type TimeFunc added in v1.3.2

type TimeFunc = func() time.Time

Jump to

Keyboard shortcuts

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