logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnrecognizedLogLevel = errors.New("unrecognized log level")

Functions

func Register

func Register(providerType string, creator ProviderCreator)

Register registers a provider by name and creator

func Stack

func Stack(calldepth int) []byte

Stack gets the call stack

func UnmarshalOpts

func UnmarshalOpts(opts string, v interface{}) error

UnmarshalOpts unmarshal JSON string opts to object v

Types

type Entry

type Entry interface {
	Level() Level
	Timestamp() int64
	Body() []byte
	Desc() []byte
	Clone() Entry
}

Entry represents a logging entry

type Handler

type Handler interface {
	Handle(entry Entry) error
}

Handler handle the logging entry

type HookableLogger

type HookableLogger interface {
	Logger
	Hook(Handler)
}

HookableLogger is a logger which can hook handlers

func New

func New(provider Provider) HookableLogger

New creates async logger with provider

func NewLoggerForTest

func NewLoggerForTest(provider Provider, async bool, with bool) HookableLogger

(NOTE): NewLoggerForTest creates a logger for testing

func NewSync

func NewSync(provider Provider) HookableLogger

NewSync creates a sync logger with provider

type Level

type Level int32

Level represents log level

const (
	FATAL Level = iota
	ERROR
	WARN
	INFO
	DEBUG
	TRACE
	NumLevel
)

func MustParseLevel

func MustParseLevel(s string) Level

MustParseLevel similars to ParseLevel, but panic if parse fail

func ParseLevel

func ParseLevel(s string) (lv Level, ok bool)

ParseLevel parses log level from string

func (*Level) Decode

func (level *Level) Decode(s string) error

func (Level) String

func (level Level) String() string

type Logger

type Logger interface {
	// Run startup logger
	Run()
	// Quit quits logger
	Quit()
	// NoHeader ignores header while output logs
	NoHeader()
	// GetLevel gets current log level
	GetLevel() Level
	// SetLevel sets log level
	SetLevel(level Level)
	// Trace outputs trace-level logs
	Trace(calldepth int, format string, args ...interface{})
	// Debug outputs debug-level logs
	Debug(calldepth int, format string, args ...interface{})
	// Info outputs info-level logs
	Info(calldepth int, format string, args ...interface{})
	// Warn outputs warn-level logs
	Warn(calldepth int, format string, args ...interface{})
	// Error outputs error-level logs
	Error(calldepth int, format string, args ...interface{})
	// Fatal outputs fatal-level logs
	Fatal(calldepth int, format string, args ...interface{})
}

Logger is the top-level object of log package

func NewStdLogger

func NewStdLogger() Logger

NewStdLogger creates std logger

func NewTestingLogger

func NewTestingLogger(t *testing.T) Logger

NewTestingLogger creates testing logger

type Provider

type Provider interface {
	Write(level Level, headerLength int, data []byte) error
	Close() error
}

Provider define an interface for writing logs

type ProviderCreator

type ProviderCreator func(opts string) Provider

ProviderCreator is a factory function type for creating Provider

func Lookup

func Lookup(providerType string) ProviderCreator

Lookup gets provider creator by name

type With

type With interface {
	LogWith(level Level, calldepth int, data []byte, format string, args ...interface{})
}

Jump to

Keyboard shortcuts

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