diff --git a/log.go b/log.go index ed13b84..8037052 100644 --- a/log.go +++ b/log.go @@ -107,13 +107,13 @@ func (l *Logger) output(lev Llevel, depth int, fields H, v ...interface{}) { Message: msg, Level: lev, Time: time.Now(), - Caller: caller(depth), + Caller: Caller(depth), Color: l.color, } switch lev { case Lerror: if !PROD { - data.Stack = stack() + data.Stack = Stack() } // disable stack trace on debug // case Ldebug: diff --git a/log_test.go b/log_test.go index 2daaa93..95f0a8e 100644 --- a/log_test.go +++ b/log_test.go @@ -210,7 +210,7 @@ func BenchmarkStackSTDStr(b *testing.B) { l.SetErrOutput(io.Discard) l.SetOutput(io.Discard) for i := 0; i < b.N; i++ { - l.Info(stack()) + l.Info(Stack()) } } @@ -220,7 +220,7 @@ func BenchmarkStackCust(b *testing.B) { l.SetErrOutput(io.Discard) l.SetOutput(io.Discard) for i := 0; i < b.N; i++ { - l.Info(Stack(3)) + l.Info(StackSkip(3)) } } @@ -230,6 +230,6 @@ func BenchmarkStackCustStr(b *testing.B) { l.SetErrOutput(io.Discard) l.SetOutput(io.Discard) for i := 0; i < b.N; i++ { - l.Info(string(Stack(3))) + l.Info(string(StackSkip(3))) } } diff --git a/util.go b/util.go index 07e28e3..457ae7f 100644 --- a/util.go +++ b/util.go @@ -7,7 +7,7 @@ import ( "runtime" ) -func caller(depth int) string { +func Caller(depth int) string { _, file, line, _ := runtime.Caller(depth) short := file for i := len(file) - 1; i > 0; i-- { @@ -19,7 +19,7 @@ func caller(depth int) string { return fmt.Sprintf("%s:%d", short, line) } -func stack() string { +func Stack() string { buf := make([]byte, 1024) for { n := runtime.Stack(buf, false) @@ -49,7 +49,7 @@ var ( ) // Stack returns a nicely formatted stack frame, skipping skip frames. -func Stack(skip int) []byte { +func StackSkip(skip int) []byte { buf := new(bytes.Buffer) // the returned data // As we loop, we open files and read them. These variables record the currently // loaded file.