logger

package
v3.0.0-...-c194909 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 9 Imported by: 0

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 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