From a62c16cbdacc61744825a9b190f762f371aba6c0 Mon Sep 17 00:00:00 2001 From: "marko.tikvic" Date: Mon, 11 Feb 2019 12:30:28 +0100 Subject: [PATCH] more detailed printing --- main.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index b7c3bdd..a968379 100644 --- a/main.go +++ b/main.go @@ -60,11 +60,6 @@ func New(name string, maxFileSize int64) (logger *Logger, err error) { return logger, nil } -func (l *Logger) Print(format string, v ...interface{}) { - msg := fmt.Sprintf(format, v...) - fmt.Printf(time.Now().Format(time.RFC3339) + ": " + msg + "\n") -} - func (l *Logger) Log(format string, v ...interface{}) { if l.outputFile == nil { return @@ -121,6 +116,13 @@ func (l *Logger) CombineHTTPLogs(in string, out string) { l.outputFile.WriteString(msg) } +func (l *Logger) Print(format string, v ...interface{}) { + _, file, line, _ := runtime.Caller(1) + + msg := fmt.Sprintf(format, v...) + fmt.Printf("%s: %s %d: %s\n", time.Now().Format(time.RFC3339), file, line, msg) +} + func (l *Logger) Trace(format string, v ...interface{}) { if l.outputFile == nil { return @@ -128,15 +130,11 @@ func (l *Logger) Trace(format string, v ...interface{}) { l.mu.Lock() defer l.mu.Unlock() - _, file, line, ok := runtime.Caller(1) - s := "" + _, file, line, _ := runtime.Caller(1) msg := fmt.Sprintf(format, v...) - if ok { - s = fmt.Sprintf("%s: %s %d: %s\n", time.Now().Format(time.RFC3339), file, line, msg) - } else { - s = fmt.Sprintf(time.Now().Format(time.RFC3339) + ": [can't retreive stack details]:" + msg + "\n") - } + s := fmt.Sprintf("%s: %s %d: %s\n", time.Now().Format(time.RFC3339), file, line, msg) + if l.shouldSplit(len(s)) { l.split() } -- 1.8.1.2