logkit

package
v0.0.0-...-9e9b37c Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string, args ...Field) error

func Error

func Error(ctx context.Context, msg string, args ...Field) error

func Info

func Info(ctx context.Context, msg string, args ...Field) error

func PrintValue

func PrintValue(w io.Writer, field Field)

func PrintValues

func PrintValues(w io.Writer, fields []Field)

func Warn

func Warn(ctx context.Context, msg string, args ...Field) error

Types

type BufferedEventsFilter

type BufferedEventsFilter func([]Event) []Event

type Context

type Context struct {
	context.Context
	Fields []Field
	Output Output
	Parent *Context
	Name   string
	Start  time.Time
	End    time.Time
}

Context implements context.Context and adds some convinience logging methods like ctx.Info("Msg")

func Operation

func Operation(ctx context.Context, name string, fields ...Field) (*Context, func())

func OperationWithOutput

func OperationWithOutput(ctx context.Context, name string, output Output, fields ...Field) (*Context, func())

func (*Context) Debug

func (c *Context) Debug(msg string, fields ...Field) error

func (*Context) Error

func (c *Context) Error(msg string, fields ...Field) error

func (*Context) Info

func (c *Context) Info(msg string, fields ...Field) error

func (*Context) Warn

func (c *Context) Warn(msg string, fields ...Field) error

type Event

type Event struct {
	Message   string
	Type      EventType
	Operation *Context
	Fields    []Field
}

func (Event) Error

func (m Event) Error() string

func (Event) String

func (m Event) String() string

type EventType

type EventType uint8
const (
	EventTypeBeginOperation EventType = iota
	EventTypeCompleteOperation
	EventTypeDebug
	EventTypeInfo
	EventTypeWarn
	EventTypeError
)

type Field

type Field struct {
	Key       string
	FieldType FieldType
	Integer   int64
	Str       string
	Value     interface{}
}

func Bool

func Bool(key string, value bool) Field

func Bytes

func Bytes(key string, value []byte) Field

func Duration

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

func Err

func Err(err error) Field

func Int

func Int(key string, value int) Field

func Int64

func Int64(key string, value int64) Field

func Interface

func Interface(key string, value interface{}) Field

func String

func String(key string, value string) Field

func Stringer

func Stringer(key string, value fmt.Stringer) Field

func Time

func Time(key string, value time.Time) Field

type FieldType

type FieldType uint8
const (
	FieldTypeUnknown FieldType = iota
	FieldTypeString
	FieldTypeInt64
	FieldTypeBytes
	FieldTypeDuration
	FieldTypeTime
	FieldTypeErr
	FieldTypeStringer
	FieldTypeBool
	FieldTypeInterface
)

type Output

type Output interface {
	Event(msg Event)
}
var DefaultOutput Output = &WriterOutput{
	output:        os.Stdout,
	colors:        isatty.IsTerminal(os.Stdout.Fd()),
	printDuration: time.Millisecond * 20,
}

DefaultOuput is the default Output for all logging

func NewBufferedOutput

func NewBufferedOutput(parent Output, filter BufferedEventsFilter) Output

func NewOutputFilter

func NewOutputFilter(parent Output, writeOperationBegin, writeOperationComplete, writeDebug, writeInfo, writeWarn, writeError bool) Output

func NewSplitterOutput

func NewSplitterOutput(targets ...Output) Output

func NewWriterOutput

func NewWriterOutput(output io.Writer, terminalColors bool, printDuration time.Duration) Output

type OutputFilter

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

func (*OutputFilter) Event

func (d *OutputFilter) Event(evt Event)

type SplitterOutput

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

func (*SplitterOutput) Event

func (d *SplitterOutput) Event(evt Event)

type WriterOutput

type WriterOutput struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*WriterOutput) Event

func (d *WriterOutput) Event(evt Event)

Jump to

Keyboard shortcuts

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