package utils

import (
	"fmt"
	"os"
	"strings"
	"time"
)

// ErrorOutput 修改该函数可以切换错误输出方式
var ErrorOutput = func(msg string) (n int, err error) {
	t := time.Now().Format("2006-01-02T15:04:05.000Z07:00")
	if strings.LastIndex(msg, "\n") > 0 {
		return fmt.Fprint(os.Stderr, t+" "+msg)
	}
	return fmt.Fprintln(os.Stderr, t+" "+msg)
}

func CatchPanic() {
	if xErr := recover(); xErr != nil {
		_, _ = ErrorOutput(fmt.Sprint(xErr))
	}
}
