From 58fb9e94de0a633eb914eae5b4627b558e6d2651 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 9 Jan 2018 14:06:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89glog=20backtrace=E6=A0=87?= =?UTF-8?q?=E5=87=86=E5=BA=93=E8=B0=83=E7=94=A8=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g/os/glog/glog.go | 6 +++--- geg/other/test.go | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/g/os/glog/glog.go b/g/os/glog/glog.go index 147078570..a4ea064a2 100644 --- a/g/os/glog/glog.go +++ b/g/os/glog/glog.go @@ -290,15 +290,15 @@ func (l *Logger) errPrint(s string) { // 调用回溯字符串 func (l *Logger) backtrace() string { - backtrace := "Trace:\n" + backtraces := []string{"Trace:"} for i := 1; i < 100; i++ { if _, cfile, cline, ok := runtime.Caller(i + 3); ok { - backtrace += strconv.Itoa(i) + ". " + cfile + ":" + strconv.Itoa(cline) + "\n" + backtraces = append(backtraces, strconv.Itoa(i) + ". " + cfile + ":" + strconv.Itoa(cline) + "\n") } else { break } } - return backtrace + return strings.Join(backtraces[0 : len(backtraces) -2 ], "\n") } func (l *Logger) format(s string) string { diff --git a/geg/other/test.go b/geg/other/test.go index 78b08c12b..49ba03def 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -2,7 +2,7 @@ package main import ( "fmt" - "reflect" + "gitee.com/johng/gf/g/os/glog" ) @@ -15,8 +15,5 @@ func (t *T)Test() { } func main() { - t := &T{"john"} - //fmt.Printf("%p\n", t.Test) - //fmt.Printf("%p\n", reflect.ValueOf(t).MethodByName("Test").Interface().(func())) - reflect.ValueOf(t).MethodByName("Test").Interface().(func())() + glog.Error("test") } \ No newline at end of file