func WithDefaultFields(fields ...Field) {
	logFields = append(logFields, fields...)
}
WithDefaultFields adds fields to the underlying logger instance
package log
import (
	"context"
	"os"
	"sync"
	"time"
	"golang.org/x/crypto/ssh/terminal"
)
var (
	bytePool = &ByteArrayPool{pool: &sync.Pool{
		New: func() interface{} {
			return make([]byte, 0, 32)
		},
	}}
	defaultHandlerRegistered = false
	defaultHandler           *console
)
func init() {
	if terminal.IsTerminal(int(os.Stdout.Fd())) {
		defaultHandler = newDefaultLogger()
		AddHandler(defaultHandler, AllLevels...)
		defaultHandlerRegistered = true
	}
}
const (
	DefaultTimeFormat = "2006-01-02T15:04:05.000000000Z07:00"
)
var (
	logFields   []Field
	logHandlers = map[Level][]Handler{}
	exitFunc    = os.Exit
	withErrFn   = errorsWithError
	ctxIdent    = &struct {
		name string
	}{
		name: "log",
	}
	rw sync.RWMutex
)
type Field struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}
func SetExitFunc(fn func(code int)) {
	exitFunc = fn
}
func SetWithErrorFn(fn func(Entry, error) Entry) {
	withErrFn = fn
}
func SetContext(ctx context.Context, e Entry) context.Context {
	return context.WithValue(ctx, ctxIdent, e)
}
func GetContext(ctx context.Context) Entry {
	v := ctx.Value(ctxIdent)
	if v == nil {
		return newEntryWithFields(nil)
	}
	return v.(Entry)
}
func BytePool() *ByteArrayPool {
	return bytePool
}
func HandleEntry(e Entry) {
	if !e.start.IsZero() {
		e = e.WithField("duration", time.Since(e.start))
	}
	e.Timestamp = time.Now()
	rw.RLock()
	for _, h := range logHandlers[e.Level] {
		h.Log(e)
	}
	rw.RUnlock()
}
func F(key string, value interface{}) Field {
	return Field{Key: key, Value: value}
}
func AddHandler(h Handler, levels ...Level) {
	rw.Lock()
	defer rw.Unlock()
	if defaultHandlerRegistered {
		removeHandler(defaultHandler)
		defaultHandler.Close()
		defaultHandler = nil
		defaultHandlerRegistered = false
	}
	for _, level := range levels {
		handler := append(logHandlers[level], h)
		logHandlers[level] = handler
	}
}
func RemoveHandler(h Handler) {
	rw.Lock()
	removeHandler(h)
	rw.Unlock()
}
func removeHandler(h Handler) {
OUTER:
	for lvl, handlers := range logHandlers {
		for i, handler := range handlers {
			if h == handler {
				n := append(handlers[:i], handlers[i+1:]...)
				if len(n) == 0 {
					delete(logHandlers, lvl)
					continue OUTER
				}
				logHandlers[lvl] = n
				continue OUTER
			}
		}
	}
}
func RemoveHandlerLevels(h Handler, levels ...Level) {
	rw.Lock()
	defer rw.Unlock()
OUTER:
	for _, lvl := range levels {
		handlers := logHandlers[lvl]
		for i, handler := range handlers {
			if h == handler {
				n := append(handlers[:i], handlers[i+1:]...)
				if len(n) == 0 {
					delete(logHandlers, lvl)
					continue OUTER
				}
				logHandlers[lvl] = n
				continue OUTER
			}
		}
	}
}