log

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 11 Imported by: 0

README

log

A structured logging package for the Go programming language.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoColor = !isatty.IsTerminal(os.Stdout.Fd())

Functions

func Color

func Color(value ...Attribute) func(io.Writer, ...interface{})

func New

func New(w io.Writer, l Level, tag string) *logger

Types

type Attribute

type Attribute int
const (
	Reset Attribute = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)
const (
	FgBlack Attribute = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)
const (
	FgHiBlack Attribute = iota + 90
	FgHiRed
	FgHiGreen
	FgHiYellow
	FgHiBlue
	FgHiMagenta
	FgHiCyan
	FgHiWhite
)
const (
	BgBlack Attribute = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)
const (
	BgHiBlack Attribute = iota + 100
	BgHiRed
	BgHiGreen
	BgHiYellow
	BgHiBlue
	BgHiMagenta
	BgHiCyan
	BgHiWhite
)

type Entry

type Entry interface {
	Logger
	Fielder
	Reader
	Created() time.Time
	SetEntryLevel(l Level)
	EntryLevel() Level
}

type Field

type Field struct {
	Order int
	Key   string
	Value interface{}
}

type Fielder

type Fielder interface {
	Fields() []Field
}

type FieldsSort

type FieldsSort []Field

func (FieldsSort) Len

func (f FieldsSort) Len() int

func (FieldsSort) Less

func (f FieldsSort) Less(i, j int) bool

func (FieldsSort) Swap

func (f FieldsSort) Swap(i, j int)

type Formatter

type Formatter interface {
	Format(Entry) ([]byte, error)
}

func DefaultNullFormatter

func DefaultNullFormatter() Formatter

func DefaultRawFormatter

func DefaultRawFormatter() Formatter

func MakeTextFormatter

func MakeTextFormatter(name string) Formatter

type FormatterManager

type FormatterManager interface {
	SetFormatter(string, Formatter)
	GetFormatter(string) Formatter
	SwapFormatter(string)
}

type Hook

type Hook interface {
	Fire(Entry) error
}

type HookFunc

type HookFunc func(Entry) error

type Hooks

type Hooks interface {
	AddHook(Timing, Level, ...Hook)
	Fire(Timing, Level, Entry) error
}

type Level

type Level int
const (
	LUnrecognized Level = iota //
	LPanic                     //
	LFatal                     //
	LError                     //
	LWarn                      //
	LInfo                      //
	LDebug                     //
)

func StringToLevel

func StringToLevel(lv string) Level

func (Level) Color

func (lv Level) Color() func(io.Writer, ...interface{})

func (Level) String

func (l Level) String() string

type Mutex

type Mutex interface {
	Lock()
	Unlock()
}

Package level mutex to prevent interference with other mutexes.

type NullFormatter

type NullFormatter struct{}

func (*NullFormatter) Format

func (n *NullFormatter) Format(e Entry) ([]byte, error)

type RawFormatter

type RawFormatter struct{}

func (*RawFormatter) Format

func (r *RawFormatter) Format(e Entry) ([]byte, error)

type Reader

type Reader interface {
	Read() (*bytes.Buffer, error)
}

type StdLogger

type StdLogger interface {
	Fatal(...interface{})
	Fatalf(string, ...interface{})
	Fatalln(...interface{})
	Panic(...interface{})
	Panicf(string, ...interface{})
	Panicln(...interface{})
	Print(...interface{})
	Printf(string, ...interface{})
	Println(...interface{})
}

An interface to some methods of the standard library log package.

type StrLogger

type StrLogger interface {
	Level() Level
}

A interface to package local structured logging.

type TextFormatter

type TextFormatter struct {
	Name            string
	TimestampFormat string
	Sort            bool
}

A text formatter

Uses the package color functions (linux only) and involves a bit of overengineering with text.template where string+" " or fmt.Sprintf would work(this provides multiple templating options to work with in formatting as opposed to appending or formatting by package fmt).

If minimalism is your thing, rewrite this.

func (*TextFormatter) Format

func (t *TextFormatter) Format(e Entry) ([]byte, error)

type Timing

type Timing int
const (
	PRE Timing = iota
	POST
)

type TmplBase

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

type XtrLogger

type XtrLogger interface {
	At(Level, ...interface{})
	Atf(Level, string, ...interface{})
	AtTo(Level, io.Writer, ...interface{})
	AtTof(Level, io.Writer, string, ...interface{})
	Log(Entry)
}

An interface to package local logging functionality.

Jump to

Keyboard shortcuts

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