func CallerStackHandler(format string, h Handler) Handler {
	return FuncHandler(h.MaxLevel(), func(r *Record) error {
		s := stack.Trace().TrimBelow(r.Call).TrimRuntime()
		if len(s) > 0 {
			r.Ctx = append(r.Ctx, "stack", fmt.Sprintf(format, s))
		}
		return h.Log(r)
	})
}
CallerStackHandler returns a Handler that adds a stack trace to the context
with key "stack". The stack trace is formated as a space separated list of
call sites inside matching []'s. The most recent call site is listed first.
Each call site is formatted according to format. See the documentation of
package github.com/go-stack/stack for the list of supported formats.
package log15
import (
	"fmt"
	"io"
	"net"
	"os"
	"reflect"
	"sync"
	"github.com/go-stack/stack"
)
type Handler interface {
	Log(r *Record) error
	MaxLevel() int
	SetMaxLevel(int)
}
func FuncHandler(maxLevel int, fn func(r *Record) error) Handler {
	return &handlebase{fn, maxLevel}
}
type handlebase struct {
	funcHandler func(r *Record) error
	maxLevel    int
}
func (h *handlebase) Log(r *Record) error {
	return h.funcHandler(r)
}
func (h *handlebase) MaxLevel() int {
	return h.maxLevel
}
func (h *handlebase) SetMaxLevel(maxLevel int) {
	h.maxLevel = maxLevel
}
func StreamHandler(wr io.Writer, fmtr Format) Handler {
	h := FuncHandler(int(LvlDebug), 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(h.MaxLevel(), func(r *Record) error {
		mu.Lock()
		err := h.Log(r)
		mu.Unlock()
		return err
	})
}
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(h.MaxLevel(), func(r *Record) error {
		r.Ctx = append(r.Ctx, "caller", fmt.Sprint(r.Call))
		return h.Log(r)
	})
}
func CallerFuncHandler(h Handler) Handler {
	return FuncHandler(h.MaxLevel(), func(r *Record) error {
		r.Ctx = append(r.Ctx, "fn", fmt.Sprintf("%+n", r.Call))
		return h.Log(r)
	})
}