mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
update
This commit is contained in:
@@ -71,5 +71,5 @@ func getCurrentDirectory() string {
|
||||
}
|
||||
|
||||
func getStr(a ...interface{}) string {
|
||||
return fmt.Sprintf(strings.Repeat("[%+v]", len(a)), a...)
|
||||
return fmt.Sprintf(strings.Repeat("[%#v]", len(a)), a...)
|
||||
}
|
||||
|
@@ -31,6 +31,15 @@ func TestZapLog(t *testing.T) {
|
||||
dev.SetService("xxjwxc")
|
||||
// dev.OnSetDev(true)
|
||||
SetLog(GetDefaultZap())
|
||||
// log.Printf("%#v", &ttt{
|
||||
// Act: "====001===",
|
||||
// Begin: time.Now().Unix(),
|
||||
// Cat: &aaa{
|
||||
// Act: "----002----",
|
||||
// Begin: time.Now().Unix(),
|
||||
// },
|
||||
// })
|
||||
// return
|
||||
|
||||
Info(&ttt{
|
||||
Act: "====001===",
|
||||
|
20
mylog/std.go
20
mylog/std.go
@@ -15,12 +15,6 @@ type stdLog struct {
|
||||
errDeal
|
||||
}
|
||||
|
||||
const ( //
|
||||
logError = iota //打印 Error 及以上级别
|
||||
logwarning //打印 warning 及以上级别
|
||||
logInfo //默认的返回值,为0,自增 //打印 Info 及以上级别
|
||||
)
|
||||
|
||||
// GetDefaultStd get default std logger
|
||||
func GetDefaultStd() *stdLog {
|
||||
return &stdLog{}
|
||||
@@ -28,7 +22,7 @@ func GetDefaultStd() *stdLog {
|
||||
|
||||
// Info level info msg
|
||||
func (s *stdLog) Info(a ...interface{}) {
|
||||
log.Println(color.FgGreen.Render(a...))
|
||||
log.Println(color.FgGreen.Render(getStr(a...)))
|
||||
}
|
||||
|
||||
// Info level info msg
|
||||
@@ -39,20 +33,20 @@ func (s *stdLog) Infof(msg string, a ...interface{}) {
|
||||
// Error 记录错误信息
|
||||
func (s *stdLog) Error(a ...interface{}) {
|
||||
// err = errors.Cause(err) //获取原始对象
|
||||
log.Println(color.Error.Render(a...))
|
||||
log.Println(color.Error.Render(getStr(a...)))
|
||||
s.SaveError(getStr(a...), "err")
|
||||
}
|
||||
|
||||
// Errorf 记录错误信息
|
||||
func (s *stdLog) Errorf(msg string, a ...interface{}) {
|
||||
log.Println(color.Error.Render(a...))
|
||||
log.Println(color.Error.Render(fmt.Sprintf(msg, a...)))
|
||||
s.SaveError(fmt.Sprintf(msg, a...), "err")
|
||||
}
|
||||
|
||||
// Debug level info msg
|
||||
func (s *stdLog) Debug(a ...interface{}) {
|
||||
if dev.IsDev() {
|
||||
log.Println(color.Debug.Render(a...))
|
||||
log.Println(color.Debug.Render(getStr(a...)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +59,7 @@ func (s *stdLog) Debugf(msg string, a ...interface{}) {
|
||||
|
||||
//Fatal 系统级错误
|
||||
func (s *stdLog) Fatal(a ...interface{}) {
|
||||
log.Output(2, color.Error.Render(fmt.Sprint(a...)))
|
||||
log.Output(2, color.Error.Render(getStr(a...)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -78,14 +72,14 @@ func (s *stdLog) Fatalf(msg string, a ...interface{}) {
|
||||
// TraceError return trace of error
|
||||
func (s *stdLog) TraceError(err error) error {
|
||||
e := errors.Cause(err) //获取原始对象
|
||||
log.Println(color.Error.Render(fmt.Sprintf(":Cause:%+v", e)))
|
||||
log.Println(color.Error.Render(getStr(e)))
|
||||
s.SaveError(getStr(err), "err")
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
// ErrorString 打印错误信息
|
||||
func (s *stdLog) ErrorString(a ...interface{}) {
|
||||
log.Output(2, color.Error.Render(fmt.Sprint(a...)))
|
||||
log.Output(2, color.Error.Render(getStr(a...)))
|
||||
}
|
||||
|
||||
func (s *stdLog) Close() {
|
||||
|
Reference in New Issue
Block a user