log

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 14 Imported by: 28

Documentation

Index

Constants

View Source
const (
	// DefaultWindow is the default message window size for rate limiting.
	DefaultWindow = 256
	// MinimumWindow is the smallest message window size for rate limiting.
	MinimumWindow = 32
)
View Source
const (
	// DefaultLevel is the default logging severity level.
	DefaultLevel = LevelInfo
)
View Source
const (
	// FmtBackendName is the name of our simple fmt-based logging backend.
	FmtBackendName = "fmt"
)

Variables

This section is empty.

Functions

func ClearDebugToggleSignal

func ClearDebugToggleSignal()

ClearDebugToggleSignal removes any signal handlers for toggling debug on/off.

func Debug

func Debug(format string, args ...interface{})

Debug formats and emits a debug message.

func DebugBlock

func DebugBlock(prefix string, format string, args ...interface{})

DebugBlock formats and emits a multiline debug message.

func DebugEnabled

func DebugEnabled(source string) bool

DebugEnabled checks if debug logging is enabled for the source.

func DisableDebug

func DisableDebug(source string) bool

DisableDebug disables debug logging for the given source.

func DisableLogging

func DisableLogging(source string) bool

DisableLogging disables non-debug logging for the given source.

func EnableDebug

func EnableDebug(source string) bool

EnableDebug enables debug logging for the source.

func EnableLogging

func EnableLogging(source string) bool

EnableLogging enables non-debug logging for the source.

func Error

func Error(format string, args ...interface{})

Error formats and emits an error message.

func ErrorBlock

func ErrorBlock(prefix string, format string, args ...interface{})

ErrorBlock formats and emits a multiline error message.

func Every

func Every(interval time.Duration) goxrate.Limit

Every defines a rate limit for the given interval.

func Fatal

func Fatal(format string, args ...interface{})

Fatal formats and emits an error message and os.Exit()'s with status 1.

func Flush

func Flush()

Flush flushes any initial message buffer and turns buffering on.

func Info

func Info(format string, args ...interface{})

Info formats and emits an informational message.

func InfoBlock

func InfoBlock(prefix string, format string, args ...interface{})

InfoBlock formats and emits a multiline information message.

func LoggingEnabled

func LoggingEnabled(source string) bool

LoggingEnabled checks if non-debug logging is enabled for the source.

func Panic

func Panic(format string, args ...interface{})

Panic formats and emits an error messages, and panics with the same.

func RegisterBackend

func RegisterBackend(name string, fn BackendFn)

RegisterBackend registers a logger backend.

func SetBackend

func SetBackend(name string) error

SetBackend activates the named Backend for logging.

func SetLevel

func SetLevel(level Level)

SetLevel sets the logging severity level.

func SetupDebugToggleSignal

func SetupDebugToggleSignal(sig os.Signal)

SetupDebugToggleSignal sets up a signal handler to toggle full debugging on/off.

func Sync

func Sync()

Sync waits for all current messages to get processed.

func Warn

func Warn(format string, args ...interface{})

Warn formats and emits a warning message.

func WarnBlock

func WarnBlock(prefix string, format string, args ...interface{})

WarnBlock formats and emits a multiline warning message.

Types

type Backend

type Backend interface {
	// Name returns the name of this backend.
	Name() string
	// Log emits log messages with the given severity, source, and Printf-like arguments.
	Log(Level, string, string, ...interface{})
	// Block emits a multi-line log messages, with an additional line prefix.
	Block(Level, string, string, string, ...interface{})
	// Flush flushes and stops initial buffering synchronously
	Flush()
	// Sync waits for all messages to get emitted.
	Sync()
	// Stop stops the backend instance.
	Stop()
	// SetSourceAlignment sets the maximum prefix length for optional alignment.
	SetSourceAlignment(int)
}

Backend can format and emit log messages.

type BackendFn

type BackendFn func() Backend

BackendFn is a functions that creates a Backend instance.

type Delayed

type Delayed interface {
	String() string
}

Delayed implements delayed evaluation (can lower the overhead of suppressed log.Debug).

func Delay

func Delay(o interface{}) Delayed

Delay wraps its argument for delayed .String() evaluation.

type Level

type Level int

Level describes the severity of log messages.

const (
	// LevelDebug is the severity for debug messages.
	LevelDebug Level = iota
	// LevelInfo is the severity for informational messages.
	LevelInfo
	// LevelWarn is the severity for warnings.
	LevelWarn
	// LevelError is the severity for errors.
	LevelError
	// LevelPanic is the severity for panic messages.
	LevelPanic
	// LevelFatal is the severity for fatal errors.
	LevelFatal
)

func (*Level) Set

func (l *Level) Set(value string) error

Set sets the level from the given name.

func (Level) String

func (l Level) String() string

String returns the name of the level.

type Logger

type Logger interface {
	// Debug formats and emits a debug message.
	Debug(format string, args ...interface{})
	// Info formats and emits an informational message.
	Info(format string, args ...interface{})
	// Warn formats and emits a warning message.
	Warn(format string, args ...interface{})
	// Error formats and emits an error message.
	Error(format string, args ...interface{})
	// Panic formats and emits an error message then panics with the same.
	Panic(format string, args ...interface{})
	// Fatal formats and emits an error message and os.Exit()'s with status 1.
	Fatal(format string, args ...interface{})

	// DebugBlock formats and emits a multiline debug message.
	DebugBlock(prefix string, format string, args ...interface{})
	// InfoBlock formats and emits a multiline information message.
	InfoBlock(prefix string, format string, args ...interface{})
	// WarnBlock formats and emits a multiline warning message.
	WarnBlock(prefix string, format string, args ...interface{})
	// ErrorBlock formats and emits a multiline error message.
	ErrorBlock(prefix string, format string, args ...interface{})

	// EnableDebug enables debug messages for this Logger.
	EnableDebug(bool) bool
	// DebugEnabled checks if debug messages are enabled for this Logger.
	DebugEnabled() bool

	// Source returns the source name of this Logger.
	Source() string
}

Logger is the interface for producing log messages for/from a particular source.

func Default

func Default() Logger

Default returns the default Logger.

func Get

func Get(source string) Logger

Get returns the Logger for source, creating one if necessary.

func NewLogger

func NewLogger(source string) Logger

NewLogger is an alias for Get().

func RateLimit

func RateLimit(log Logger, rate Rate) Logger

RateLimit returns a ratelimited version of the given logger.

type Rate

type Rate struct {
	// rate limit
	Limit goxrate.Limit
	// allowed bursts
	Burst int
	// optional message window size
	Window int
}

Rate specifies maximum per-message logging rate.

func Interval

func Interval(interval time.Duration) Rate

Interval returns a Rate for the given interval.

Jump to

Keyboard shortcuts

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