logl

package module
Version: v0.0.0-...-cda8c01 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: GPL-3.0 Imports: 9 Imported by: 1

README

logl

Golang logger with levels

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LevelAllow

func LevelAllow(level Level, l Logger) bool

Types

type BaseLogger

type BaseLogger interface {
	Log(level Level, vs ...interface{})
	Logf(level Level, format string, vs ...interface{})

	Level() Level
	SetLevel(Level)
}

Concept of a most simple interface:

type FormatText

type FormatText struct {
	HasLevel        bool
	HasDate         bool
	HasTime         bool
	HasMicroseconds bool
	ShieldSpecial   bool // { '\n', '\r', '\t', '\\' }
}

func (*FormatText) Format

func (f *FormatText) Format(r *Record) []byte

type Formatter

type Formatter interface {
	Format(*Record) []byte
}

func FormatJSON

func FormatJSON() Formatter

type HandleLogger

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

func NewHandleLogger

func NewHandleLogger(level Level, handler Handler) *HandleLogger

func (*HandleLogger) Critical

func (l *HandleLogger) Critical(vs ...interface{})

func (*HandleLogger) Criticalf

func (l *HandleLogger) Criticalf(format string, vs ...interface{})

func (*HandleLogger) Debug

func (l *HandleLogger) Debug(vs ...interface{})

func (*HandleLogger) Debugf

func (l *HandleLogger) Debugf(format string, vs ...interface{})

func (*HandleLogger) Error

func (l *HandleLogger) Error(vs ...interface{})

func (*HandleLogger) Errorf

func (l *HandleLogger) Errorf(format string, vs ...interface{})

func (*HandleLogger) Info

func (l *HandleLogger) Info(vs ...interface{})

func (*HandleLogger) Infof

func (l *HandleLogger) Infof(format string, vs ...interface{})

func (*HandleLogger) Level

func (l *HandleLogger) Level() Level

func (*HandleLogger) Log

func (l *HandleLogger) Log(level Level, vs ...interface{})

func (*HandleLogger) Logf

func (l *HandleLogger) Logf(level Level, format string, vs ...interface{})

func (*HandleLogger) SetHandler

func (l *HandleLogger) SetHandler(handler Handler)

func (*HandleLogger) SetLevel

func (l *HandleLogger) SetLevel(level Level)

func (*HandleLogger) Trace

func (l *HandleLogger) Trace(vs ...interface{})

func (*HandleLogger) Tracef

func (l *HandleLogger) Tracef(format string, vs ...interface{})

func (*HandleLogger) Warning

func (l *HandleLogger) Warning(vs ...interface{})

func (*HandleLogger) Warningf

func (l *HandleLogger) Warningf(format string, vs ...interface{})

type Handler

type Handler interface {
	Handle(*Record)
}
var DummyHandler Handler = dummyHandler{}

func FilterHandler

func FilterHandler(filter func(*Record) bool, handler Handler) Handler

func FuncHandler

func FuncHandler(fn func(*Record)) Handler

func MultiHandler

func MultiHandler(hs ...Handler) Handler

type Level

type Level int
const (
	LevelOff      Level = iota // log: [ ]
	LevelCritical              // log: [ Critical ]
	LevelError                 // log: [ Critical, Error ]
	LevelWarning               // log: [ Critical, Error, Warning ]
	LevelInfo                  // log: [ Critical, Error, Warning, Info ]
	LevelDebug                 // log: [ Critical, Error, Warning, Info, Debug ]
	LevelTrace                 // log: [ Critical, Error, Warning, Info, Debug, Trace ]
)

func ParseLevel

func ParseLevel(s string) (Level, error)

func (Level) MarshalText

func (l Level) MarshalText() (text []byte, err error)

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

type Logger

type Logger interface {
	BaseLogger

	Critical(vs ...interface{})
	Error(vs ...interface{})
	Warning(vs ...interface{})
	Info(vs ...interface{})
	Debug(vs ...interface{})
	Trace(vs ...interface{})

	Criticalf(format string, vs ...interface{})
	Errorf(format string, vs ...interface{})
	Warningf(format string, vs ...interface{})
	Infof(format string, vs ...interface{})
	Debugf(format string, vs ...interface{})
	Tracef(format string, vs ...interface{})
}

func MakeDummyLogger

func MakeDummyLogger() Logger

func MakeLogger

func MakeLogger(level Level, w io.Writer) Logger

func MakeStdoutLogger

func MakeStdoutLogger(level Level) Logger

type Record

type Record struct {
	Time    time.Time
	Level   Level
	Message string
}

type StreamHandler

type StreamHandler struct {
	Output io.Writer
	Format Formatter
}

func (*StreamHandler) Handle

func (p *StreamHandler) Handle(r *Record)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL