Commit ce403bd83b685a2d3585483230a8719e71e5e124
1 parent
a58576e6c5
Exists in
master
changed timestamp format to a more readable one
Showing
1 changed file
with
5 additions
and
7 deletions
Show diff stats
gologger.go
1 | -// @TODO: Implement mutex lock for files access. | |
2 | 1 | package gologger |
3 | 2 | |
4 | 3 | import ( |
5 | 4 | "fmt" |
6 | 5 | "os" |
7 | 6 | "time" |
8 | - "strconv" | |
9 | 7 | "sync" |
10 | 8 | ) |
11 | 9 | |
... | ... | @@ -32,7 +30,7 @@ func NewLogger(eventFileName, errorFileName string) (*Logger, error) { |
32 | 30 | var l Logger |
33 | 31 | var err error |
34 | 32 | |
35 | - timestamp := "_" + strconv.FormatInt(time.Now().Unix(), 10) | |
33 | + timestamp := "_" + time.Now().Format(time.RFC3339) | |
36 | 34 | |
37 | 35 | // create files |
38 | 36 | l.eventFileName = eventFileName |
... | ... | @@ -88,7 +86,7 @@ func (l *Logger) Close() { |
88 | 86 | } |
89 | 87 | |
90 | 88 | func (l *Logger) splitEventLog() { |
91 | - timestamp := "_" + strconv.FormatInt(time.Now().Unix(), 10) | |
89 | + timestamp := "_" + time.Now().Format(time.RFC3339) | |
92 | 90 | |
93 | 91 | evfstats, _ := l.eventf.Stat() |
94 | 92 | if evfstats.Size() >= MaxLogFileSize100KB { |
... | ... | @@ -110,7 +108,7 @@ func (l *Logger) splitEventLog() { |
110 | 108 | } |
111 | 109 | |
112 | 110 | func (l *Logger) splitErrorLog() { |
113 | - timestamp := "_" + strconv.FormatInt(time.Now().Unix(), 10) | |
111 | + timestamp := "_" + time.Now().Format(time.RFC3339) | |
114 | 112 | |
115 | 113 | erfstats, _ := l.errorf.Stat() |
116 | 114 | if erfstats.Size() >= MaxLogFileSize100KB { |
... | ... | @@ -134,13 +132,13 @@ func (l *Logger) splitErrorLog() { |
134 | 132 | func (l *Logger) LogEvent(event string) { |
135 | 133 | muEv.Lock() |
136 | 134 | defer muEv.Unlock() |
137 | - l.eventf.WriteString(time.Now().Format(time.UnixDate) + ": " + event + "\n") | |
135 | + l.eventf.WriteString(time.Now().Format(time.RFC3339) + ": " + event + "\n") | |
138 | 136 | l.splitEventLog() |
139 | 137 | } |
140 | 138 | |
141 | 139 | func (l *Logger) LogError(err error) { |
142 | 140 | muEr.Lock() |
143 | 141 | defer muEr.Unlock() |
144 | - l.errorf.WriteString(time.Now().Format(time.UnixDate) + ": " + err.Error() + "\n") | |
142 | + l.errorf.WriteString(time.Now().Format(time.RFC3339) + ": " + err.Error() + "\n") | |
145 | 143 | l.splitErrorLog() |
146 | 144 | } | ... | ... |