diff --git a/logger/logger.go b/logger/logger.go index 75324d7..296a0af 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -28,9 +28,10 @@ type Logger struct { fatalFunc func(err interface{}) } -func Lshortfile() string { +// Lshortfile is a re-implemented log.Lshortfile with a modifiable call level. +func Lshortfile(level int) string { // 0 = This function, 1 = Print/Printf/Println, 2 = Caller of Print/Printf/Println - _, file, line, ok := runtime.Caller(2) + _, file, line, ok := runtime.Caller(level) lineString := strconv.Itoa(line) if !ok { return "" @@ -47,6 +48,10 @@ func Lshortfile() string { return file + ":" + lineString + ":" } +func lshortfile() string { + return Lshortfile(2) +} + func NewLogger(out io.Writer, prefix string, flag int, color c.Attribute) (l *Logger) { l = &Logger{} // Use reimplemented Lshortfile since wrapping the log functions messes them up @@ -73,7 +78,7 @@ func (l *Logger) Printf(format string, v ...interface{}) { } var out string if l.shortfile { - out = Lshortfile() + out = lshortfile() } out += " " + l.printer.Sprintf(format, v...) l.logger.Print(out) @@ -85,7 +90,7 @@ func (l *Logger) Print(v ...interface{}) { } var out string if l.shortfile { - out = Lshortfile() + out = lshortfile() } out += " " + l.printer.Sprint(v...) l.logger.Print(out) @@ -97,7 +102,7 @@ func (l *Logger) Println(v ...interface{}) { } var out string if l.shortfile { - out = Lshortfile() + out = lshortfile() } out += " " + l.printer.Sprintln(v...) l.logger.Print(out) @@ -109,7 +114,7 @@ func (l *Logger) Fatal(v ...interface{}) { } var out string if l.shortfile { - out = Lshortfile() + out = lshortfile() } out += " " + l.printer.Sprint(v...) l.logger.Fatal(out) @@ -121,7 +126,7 @@ func (l *Logger) Fatalf(format string, v ...interface{}) { } var out string if l.shortfile { - out = Lshortfile() + out = lshortfile() } out += " " + l.printer.Sprintf(format, v...) if l.fatalFunc != nil { diff --git a/storage.go b/storage.go index a223692..18af06d 100644 --- a/storage.go +++ b/storage.go @@ -111,7 +111,7 @@ func (st *Storage) DebugWatch(storeType StoreType, key, mainData string) { actionString = "DELETE" } if logAction == LogAll || mainData == "" { - st.debug.Printf("%s: %s[%s] = \"%s\"\n", actionString, actionKey, key, mainData) + st.debug.Printf("%s @ %s %s[%s] = \"%s\"\n", actionString, logger.Lshortfile(3), actionKey, key, mainData) } }