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() }