package ext
import "github.com/inconshreveable/log15/ext"
Index ¶
- func EscalateErrHandler(h log.Handler) log.Handler
- func FatalHandler(h log.Handler) log.Handler
- func RandId(idlen int) string
- type HotSwap
- func HotSwapHandler(h log.Handler) *HotSwap
- func (h *HotSwap) Log(r *log.Record) error
- func (h *HotSwap) Swap(newHandler log.Handler)
- type Speculative
Functions ¶
func EscalateErrHandler ¶
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 ¶
FatalHandler makes critical errors exit the program immediately, much like the log.Fatal* methods from the standard log package
func RandId ¶
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 ¶
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 ¶
Log implements log15.Handler interface.
func (*HotSwap) Swap ¶
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
Source Files ¶
- Version
- v2.16.0+incompatible (latest)
- Published
- Nov 22, 2022
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 2 weeks ago –
Tools for package owners.