Browse Source

Fatal now prints stack trace

Signed-off-by: Vishal Rana <vr@labstack.com>
Vishal Rana 9 năm trước cách đây
mục cha
commit
f8343700e8
1 tập tin đã thay đổi với 7 bổ sung1 xóa
  1. 7 1
      log/log.go

+ 7 - 1
log/log.go

@@ -42,7 +42,7 @@ const (
 var (
 	global        = New("-")
 	defaultFormat = "time=${time_rfc3339}, level=${level}, prefix=${prefix}, file=${short_file}, " +
-		"line=${line}, ${message}\n"
+		"line=${line}, message=${message}\n"
 )
 
 func New(prefix string) (l *Logger) {
@@ -51,6 +51,7 @@ func New(prefix string) (l *Logger) {
 		prefix:   prefix,
 		template: l.newTemplate(defaultFormat),
 	}
+	l.initLevels()
 	l.SetOutput(colorable.NewColorableStdout())
 	return
 }
@@ -258,6 +259,11 @@ func (l *Logger) log(v uint8, format string, args ...interface{}) {
 		} else {
 			message = fmt.Sprintf(format, args...)
 		}
+		if v == FATAL {
+			stack := make([]byte, 4<<10)
+			length := runtime.Stack(stack, true)
+			message = message + "\n" + string(stack[:length])
+		}
 		l.template.ExecuteFunc(l.output, func(w io.Writer, tag string) (int, error) {
 			switch tag {
 			case "time_rfc3339":