diff --git a/main.go b/main.go index 7d13f37..63be7a5 100644 --- a/main.go +++ b/main.go @@ -89,9 +89,16 @@ func (l *Logger) Print(format string, v ...interface{}) { fmt.Printf("%s: %s\n", time.Now().Format(dateTimeFormat), msg) } +// CallerFilenameAndLineNumber ... +func CallerFilenameAndLineNumber() (string, int) { + _, path, line, _ := runtime.Caller(1) + file := filepath.Base(path) + return file, line +} + // PrintTrace ... func (l *Logger) PrintTrace(format string, v ...interface{}) { - _, file, line, _ := runtime.Caller(1) + file, line := CallerFilenameAndLineNumber() msg := fmt.Sprintf(format, v...) fmt.Printf("%s: %s %d: %s\n", time.Now().Format(dateTimeFormat), file, line, msg) @@ -106,7 +113,8 @@ func (l *Logger) Trace(format string, v ...interface{}) { l.mu.Lock() defer l.mu.Unlock() - _, file, line, _ := runtime.Caller(1) + file, line := CallerFilenameAndLineNumber() + msg := fmt.Sprintf(format, v...) s := fmt.Sprintf("%s: %s %d: %s\n", time.Now().Format(dateTimeFormat), file, line, msg)