func LazyHandler(h Handler) Handler {
	return FuncHandler(func(r *Record) error {
		hadErr := false
		for i := 1; i < len(r.Ctx); i += 2 {
			lz, ok := r.Ctx[i].(Lazy)
			if ok {
				v, err := evaluateLazy(lz)
				if err != nil {
					hadErr = true
					r.Ctx[i] = err
				} else {
					if cs, ok := v.(stack.Trace); ok {
						v = cs.TrimBelow(stack.Call(r.CallPC[0])).
							TrimRuntime()
					}
					r.Ctx[i] = v
				}
			}
		}
		if hadErr {
			r.Ctx = append(r.Ctx, errorKey, "bad lazy")
		}
		return h.Log(r)
	})
}
LazyHandler writes all values to the wrapped handler after evaluating
any lazy functions in the record's context. It is already wrapped
around StreamHandler and SyslogHandler in this library, you'll only need
it if you write your own Handler.
package log15
import (
	"bytes"
	"fmt"
	"io"
	"net"
	"os"
	"reflect"
	"sync"
	"gopkg.in/inconshreveable/log15.v2/stack"
)
type Handler interface {
	Log(r *Record) error
}
func FuncHandler(fn func(r *Record) error) Handler {
	return funcHandler(fn)
}
type funcHandler func(r *Record) error
func (h funcHandler) Log(r *Record) error {
	return h(r)
}
func StreamHandler(wr io.Writer, fmtr Format) Handler {
	h := FuncHandler(func(r *Record) error {
		_, err := wr.Write(fmtr.Format(r))
		return err
	})
	return LazyHandler(SyncHandler(h))
}
func SyncHandler(h Handler) Handler {
	var mu sync.Mutex
	return FuncHandler(func(r *Record) error {
		defer mu.Unlock()
		mu.Lock()
		return h.Log(r)
	})
}
func FileHandler(path string, fmtr Format) (Handler, error) {
	f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
	if err != nil {
		return nil, err
	}
	return closingHandler{f, StreamHandler(f, fmtr)}, nil
}
func NetHandler(network, addr string, fmtr Format) (Handler, error) {
	conn, err := net.Dial(network, addr)
	if err != nil {
		return nil, err
	}
	return closingHandler{conn, StreamHandler(conn, fmtr)}, nil
}
type closingHandler struct {
	io.WriteCloser
	Handler
}
func (h *closingHandler) Close() error {
	return h.WriteCloser.Close()
}
func CallerFileHandler(h Handler) Handler {
	return FuncHandler(func(r *Record) error {
		call := stack.Call(r.CallPC[0])
		r.Ctx = append(r.Ctx, "caller", fmt.Sprint(call))
		return h.Log(r)
	})
}
func CallerFuncHandler(h Handler) Handler {
	return FuncHandler(func(r *Record) error {
		call := stack.Call(r.CallPC[0])
		r.Ctx = append(r.Ctx, "fn", fmt.Sprintf("%+n", call))
		return h.Log(r)
	})
}
func CallerStackHandler(format string, h Handler) Handler {
	return FuncHandler(func(r *Record) error {
		s := stack.Callers().
			TrimBelow(stack.Call(r.CallPC[0])).
			TrimRuntime()
		if len(s) > 0 {
			buf := &bytes.Buffer{}
			buf.WriteByte('[')
			for i, pc := range s {
				if i > 0 {
					buf.WriteByte(' ')
				}
				fmt.Fprintf(buf, format, pc)
			}
			buf.WriteByte(']')
			r.Ctx = append(r.Ctx, "stack", buf.String())
		}
		return h.Log(r)
	})
}
func FilterHandler(fn func(r *Record) bool, h Handler) Handler {
	return FuncHandler(func(r *Record) error {
		if fn(r) {
			return h.Log(r)
		}
		return nil
	})
}
func MatchFilterHandler(key string, value interface{}, h Handler) Handler {
	return FilterHandler(func(r *Record) (pass bool) {
		switch key {
		case r.KeyNames.Lvl:
			return r.Lvl == value
		case r.KeyNames.Time:
			return r.Time == value
		case r.KeyNames.Msg:
			return r.Msg == value
		}
		for i := 0; i < len(r.Ctx); i += 2 {
			if r.Ctx[i] == key {
				return r.Ctx[i+1] == value
			}
		}
		return false
	}, h)
}
func LvlFilterHandler(maxLvl Lvl, h Handler) Handler {
	return FilterHandler(func(r *Record) (pass bool) {
		return r.Lvl <= maxLvl
	}, h)
}
func MultiHandler(hs ...Handler) Handler {
	return FuncHandler(func(r *Record) error {
		for _, h := range hs {
			h.Log(r)
		}
		return nil
	})
}
func FailoverHandler(hs ...Handler) Handler {
	return FuncHandler(func(r *Record) error {
		var err error
		for i, h := range hs {
			err = h.Log(r)
			if err == nil {
				return nil
			} else {
				r.Ctx = append(r.Ctx, fmt.Sprintf("failover_err_%d", i), err)
			}
		}
		return err
	})
}
func ChannelHandler(recs chan<- *Record) Handler {
	return FuncHandler(func(r *Record) error {
		recs <- r
		return nil
	})
}
func BufferedHandler(bufSize int, h Handler) Handler {
	recs := make(chan *Record, bufSize)
	go func() {
		for m := range recs {
			_ = h.Log(m)
		}
	}()
	return ChannelHandler(recs)
}