diff options
Diffstat (limited to 'vendor/github.com/labstack/gommon/log/log.go')
-rw-r--r-- | vendor/github.com/labstack/gommon/log/log.go | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/vendor/github.com/labstack/gommon/log/log.go b/vendor/github.com/labstack/gommon/log/log.go index 1ac6c00c..132411db 100644 --- a/vendor/github.com/labstack/gommon/log/log.go +++ b/vendor/github.com/labstack/gommon/log/log.go @@ -8,11 +8,10 @@ import ( "os" "path" "runtime" + "strconv" "sync" "time" - "strconv" - "github.com/mattn/go-isatty" "github.com/valyala/fasttemplate" @@ -23,6 +22,7 @@ type ( Logger struct { prefix string level Lvl + skip int output io.Writer template *fasttemplate.Template levels []string @@ -42,6 +42,8 @@ const ( WARN ERROR OFF + panicLevel + fatalLevel ) var ( @@ -50,9 +52,14 @@ var ( `"file":"${short_file}","line":"${line}"}` ) +func init() { + global.skip = 3 +} + func New(prefix string) (l *Logger) { l = &Logger{ level: INFO, + skip: 2, prefix: prefix, template: l.newTemplate(defaultHeader), color: color.New(), @@ -74,6 +81,9 @@ func (l *Logger) initLevels() { l.color.Green("INFO"), l.color.Yellow("WARN"), l.color.Red("ERROR"), + "", + l.color.Yellow("PANIC", color.U), + l.color.Red("FATAL", color.U), } } @@ -188,32 +198,32 @@ func (l *Logger) Errorj(j JSON) { } func (l *Logger) Fatal(i ...interface{}) { - l.Print(i...) + l.log(fatalLevel, "", i...) os.Exit(1) } func (l *Logger) Fatalf(format string, args ...interface{}) { - l.Printf(format, args...) + l.log(fatalLevel, format, args...) os.Exit(1) } func (l *Logger) Fatalj(j JSON) { - l.Printj(j) + l.log(fatalLevel, "json", j) os.Exit(1) } func (l *Logger) Panic(i ...interface{}) { - l.Print(i...) + l.log(panicLevel, "", i...) panic(fmt.Sprint(i...)) } func (l *Logger) Panicf(format string, args ...interface{}) { - l.Printf(format, args...) - panic(fmt.Sprintf(format, args)) + l.log(panicLevel, format, args...) + panic(fmt.Sprintf(format, args...)) } func (l *Logger) Panicj(j JSON) { - l.Printj(j) + l.log(panicLevel, "json", j) panic(j) } @@ -343,7 +353,7 @@ func (l *Logger) log(v Lvl, format string, args ...interface{}) { buf := l.bufferPool.Get().(*bytes.Buffer) buf.Reset() defer l.bufferPool.Put(buf) - _, file, line, _ := runtime.Caller(3) + _, file, line, _ := runtime.Caller(l.skip) if v >= l.level || v == 0 { message := "" |