ext

package
v0.0.0-...-a0377a5 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscalateErrHandler

func EscalateErrHandler(h log.Handler) log.Handler

EscalateErrHandler wraps another handler and passes all records through unchanged except if the logged context contains a non-nil error value in its context. In that case, the record's level is raised to LvlError unless it was already more serious (LvlCrit).

This allows you to log the result of all functions for debugging and still capture error conditions when in production with a single log line. As an example, the following the log record will be written out only if there was an error writing a value to redis:

logger := logext.EscalateErrHandler(
    log.LvlFilterHandler(log.LvlInfo, log.StdoutHandler))

reply, err := redisConn.Do("SET", "foo", "bar")
logger.Debug("Wrote value to redis", "reply", reply, "err", err)
if err != nil {
    return err
}

func FatalHandler

func FatalHandler(h log.Handler) log.Handler

FatalHandler makes critical errors exit the program immediately, much like the log.Fatal* methods from the standard log package

func RandId

func RandId(idlen int) string

RandId creates a random identifier of the requested length. Useful for assigning mostly-unique identifiers for logging and identification that are unlikely to collide because of short lifespan or low set cardinality

Types

type HotSwap

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

HotSwap is the Log15.Handler. Read `HotSwapHandler` for more information.

func HotSwapHandler

func HotSwapHandler(h log.Handler) *HotSwap

HotSwapHandler wraps another handler that may swapped out dynamically at runtime in a thread-safe fashion. HotSwapHandler is the same functionality used to implement the SetHandler method for the default implementation of Logger.

func (*HotSwap) Log

func (h *HotSwap) Log(r *log.Record) error

Log implements log15.Handler interface.

func (*HotSwap) Swap

func (h *HotSwap) Swap(newHandler log.Handler)

Swap atomically the logger handler.

type Speculative

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

Speculative is the Log15.Handler. Read `SpeculativeHandler` for more information.

func SpeculativeHandler

func SpeculativeHandler(size int, h log.Handler) *Speculative

SpeculativeHandler is a handler for speculative logging. It keeps a ring buffer of the given size full of the last events logged into it. When Flush is called, all buffered log records are written to the wrapped handler. This is extremely for continuosly capturing debug level output, but only flushing those log records if an exceptional condition is encountered.

func (*Speculative) Flush

func (h *Speculative) Flush()

Flush logs all records on the handler.

func (*Speculative) Log

func (h *Speculative) Log(r *log.Record) error

Log implements log15.Handler interface

Jump to

Keyboard shortcuts

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