From 132f8f2cba2cdd51cd6b3e7c0d8cf9c29c7b5b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Thu, 1 Jun 2017 10:55:46 +0200 Subject: [PATCH] Logger can now print filename and line number --- gologger.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gologger.go b/gologger.go index a545494..37737d3 100644 --- a/gologger.go +++ b/gologger.go @@ -5,6 +5,7 @@ import ( "os" "sync" "time" + "runtime" ) var muEv = &sync.Mutex{} @@ -142,3 +143,31 @@ func (l *Logger) LogError(comment string, err error) { l.errorf.WriteString(time.Now().Format(time.RFC3339) + ": " + comment + ": " + err.Error() + "\n") l.splitErrorLog() } + +func (l *Logger) LogDetailedEvent(event string) { + muEv.Lock() + defer muEv.Unlock() + _, file, line, ok := runtime.Caller(1) + var s string + if ok { + s = fmt.Sprintf("%s: %s %d: %s\n", time.Now().Format(time.RFC3339), file, line, event) + } else { + s = fmt.Sprintf(time.Now().Format(time.RFC3339) + ": [can't retreive stack details]:" + event + "\n") + } + l.eventf.WriteString(s) + l.splitEventLog() +} + +func (l *Logger) LogDetailedError(err error) { + muEr.Lock() + defer muEr.Unlock() + _, file, line, ok := runtime.Caller(1) + var s string + if ok { + s = fmt.Sprintf("%s %s %d: %s\n", time.Now().Format(time.RFC3339), file, line, err.Error()) + } else { + s = fmt.Sprintf(time.Now().Format(time.RFC3339) + ": [can't retreive stack details]:" + err.Error() + "\n") + } + l.errorf.WriteString(s) + l.splitErrorLog() +} -- 1.8.1.2