logger

package
v3.26.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: MIT Imports: 9 Imported by: 9

Documentation

Index

Constants

View Source
const (
	DateFormat = "2006-01-02 15:04:05"
)

Variables

View Source
var Discard = &ConsoleLogger{
	printer: &TextPrinter{
		Writer: ioutil.Discard,
	},
}

Functions

func ColorsSupported

func ColorsSupported() bool

Types

type Buffer added in v3.24.0

type Buffer struct {
	Messages []string
}

Buffer is a Logger implementation intended for testing; messages are stored internally.

func NewBuffer added in v3.25.0

func NewBuffer() *Buffer

NewBuffer creates a new Buffer with Messages slice initialized. This makes it simpler to assert empty []string when no log messages have been sent; otherwise Messages would be nil.

func (*Buffer) Debug added in v3.24.0

func (b *Buffer) Debug(format string, v ...interface{})

func (*Buffer) Error added in v3.24.0

func (b *Buffer) Error(format string, v ...interface{})

func (*Buffer) Fatal added in v3.24.0

func (b *Buffer) Fatal(format string, v ...interface{})

func (*Buffer) Info added in v3.24.0

func (b *Buffer) Info(format string, v ...interface{})

func (*Buffer) Level added in v3.24.0

func (b *Buffer) Level() Level

func (*Buffer) Notice added in v3.24.0

func (b *Buffer) Notice(format string, v ...interface{})

func (*Buffer) SetLevel added in v3.24.0

func (b *Buffer) SetLevel(level Level)

func (*Buffer) Warn added in v3.24.0

func (b *Buffer) Warn(format string, v ...interface{})

func (*Buffer) WithFields added in v3.24.0

func (b *Buffer) WithFields(fields ...Field) Logger

type ConsoleLogger

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

func (*ConsoleLogger) Debug

func (l *ConsoleLogger) Debug(format string, v ...interface{})

func (*ConsoleLogger) Error

func (l *ConsoleLogger) Error(format string, v ...interface{})

func (*ConsoleLogger) Fatal

func (l *ConsoleLogger) Fatal(format string, v ...interface{})

func (*ConsoleLogger) Info

func (l *ConsoleLogger) Info(format string, v ...interface{})

func (*ConsoleLogger) Level

func (l *ConsoleLogger) Level() Level

func (*ConsoleLogger) Notice

func (l *ConsoleLogger) Notice(format string, v ...interface{})

func (*ConsoleLogger) SetLevel

func (l *ConsoleLogger) SetLevel(level Level)

SetLevel sets the level in the logger

func (*ConsoleLogger) Warn

func (l *ConsoleLogger) Warn(format string, v ...interface{})

func (*ConsoleLogger) WithFields

func (l *ConsoleLogger) WithFields(fields ...Field) Logger

WithFields returns a copy of the logger with the provided fields

type Field

type Field interface {
	Key() string
	String() string
}

func DurationField

func DurationField(key string, value time.Duration) Field

func IntField

func IntField(key string, value int) Field

func StringField

func StringField(key, value string) Field

type Fields

type Fields []Field

func (*Fields) Add

func (f *Fields) Add(fields ...Field)

func (*Fields) Get

func (f *Fields) Get(key string) []Field

type GenericField

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

func (GenericField) Key

func (f GenericField) Key() string

func (GenericField) String

func (f GenericField) String() string

type JSONPrinter

type JSONPrinter struct {
	Writer io.Writer
}

func NewJSONPrinter

func NewJSONPrinter(w io.Writer) *JSONPrinter

func (*JSONPrinter) Print

func (p *JSONPrinter) Print(level Level, msg string, fields Fields)

type Level

type Level int
const (
	DEBUG Level = iota
	NOTICE
	INFO
	ERROR
	WARN
	FATAL
)

func (Level) String

func (p Level) String() string

String returns the string representation of a logging level.

type Logger

type Logger interface {
	Debug(format string, v ...interface{})
	Error(format string, v ...interface{})
	Fatal(format string, v ...interface{})
	Notice(format string, v ...interface{})
	Warn(format string, v ...interface{})
	Info(format string, v ...interface{})

	WithFields(fields ...Field) Logger
	SetLevel(level Level)
	Level() Level
}

func NewConsoleLogger

func NewConsoleLogger(printer Printer, exitFn func(int)) Logger

type Printer

type Printer interface {
	Print(level Level, msg string, fields Fields)
}

type TextPrinter

type TextPrinter struct {
	Colors bool
	Writer io.Writer

	IsPrefixFn  func(Field) bool
	IsVisibleFn func(Field) bool
}

func NewTextPrinter

func NewTextPrinter(w io.Writer) *TextPrinter

func (*TextPrinter) Print

func (l *TextPrinter) Print(level Level, msg string, fields Fields)

Jump to

Keyboard shortcuts

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