From ce403bd83b685a2d3585483230a8719e71e5e124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Wed, 7 Dec 2016 10:31:22 +0100 Subject: [PATCH] changed timestamp format to a more readable one --- gologger.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gologger.go b/gologger.go index 0072e03..7a4c711 100644 --- a/gologger.go +++ b/gologger.go @@ -1,11 +1,9 @@ -// @TODO: Implement mutex lock for files access. package gologger import ( "fmt" "os" "time" - "strconv" "sync" ) @@ -32,7 +30,7 @@ func NewLogger(eventFileName, errorFileName string) (*Logger, error) { var l Logger var err error - timestamp := "_" + strconv.FormatInt(time.Now().Unix(), 10) + timestamp := "_" + time.Now().Format(time.RFC3339) // create files l.eventFileName = eventFileName @@ -88,7 +86,7 @@ func (l *Logger) Close() { } func (l *Logger) splitEventLog() { - timestamp := "_" + strconv.FormatInt(time.Now().Unix(), 10) + timestamp := "_" + time.Now().Format(time.RFC3339) evfstats, _ := l.eventf.Stat() if evfstats.Size() >= MaxLogFileSize100KB { @@ -110,7 +108,7 @@ func (l *Logger) splitEventLog() { } func (l *Logger) splitErrorLog() { - timestamp := "_" + strconv.FormatInt(time.Now().Unix(), 10) + timestamp := "_" + time.Now().Format(time.RFC3339) erfstats, _ := l.errorf.Stat() if erfstats.Size() >= MaxLogFileSize100KB { @@ -134,13 +132,13 @@ func (l *Logger) splitErrorLog() { func (l *Logger) LogEvent(event string) { muEv.Lock() defer muEv.Unlock() - l.eventf.WriteString(time.Now().Format(time.UnixDate) + ": " + event + "\n") + l.eventf.WriteString(time.Now().Format(time.RFC3339) + ": " + event + "\n") l.splitEventLog() } func (l *Logger) LogError(err error) { muEr.Lock() defer muEr.Unlock() - l.errorf.WriteString(time.Now().Format(time.UnixDate) + ": " + err.Error() + "\n") + l.errorf.WriteString(time.Now().Format(time.RFC3339) + ": " + err.Error() + "\n") l.splitErrorLog() } -- 1.8.1.2