Commit 9dd4c982b887a6cdc9ef5d59d993a96193771790
1 parent
c138614d93
Exists in
master
add CallerFilenameAndLineNumber()
Showing
1 changed file
with
10 additions
and
2 deletions
Show diff stats
main.go
... | ... | @@ -89,9 +89,16 @@ func (l *Logger) Print(format string, v ...interface{}) { |
89 | 89 | fmt.Printf("%s: %s\n", time.Now().Format(dateTimeFormat), msg) |
90 | 90 | } |
91 | 91 | |
92 | +// CallerFilenameAndLineNumber ... | |
93 | +func CallerFilenameAndLineNumber() (string, int) { | |
94 | + _, path, line, _ := runtime.Caller(1) | |
95 | + file := filepath.Base(path) | |
96 | + return file, line | |
97 | +} | |
98 | + | |
92 | 99 | // PrintTrace ... |
93 | 100 | func (l *Logger) PrintTrace(format string, v ...interface{}) { |
94 | - _, file, line, _ := runtime.Caller(1) | |
101 | + file, line := CallerFilenameAndLineNumber() | |
95 | 102 | |
96 | 103 | msg := fmt.Sprintf(format, v...) |
97 | 104 | 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{}) { |
106 | 113 | l.mu.Lock() |
107 | 114 | defer l.mu.Unlock() |
108 | 115 | |
109 | - _, file, line, _ := runtime.Caller(1) | |
116 | + file, line := CallerFilenameAndLineNumber() | |
117 | + | |
110 | 118 | msg := fmt.Sprintf(format, v...) |
111 | 119 | s := fmt.Sprintf("%s: %s %d: %s\n", time.Now().Format(dateTimeFormat), file, line, msg) |
112 | 120 | ... | ... |