Commit 132f8f2cba2cdd51cd6b3e7c0d8cf9c29c7b5b07
1 parent
baa4468b76
Exists in
master
Logger can now print filename and line number
Showing
1 changed file
with
29 additions
and
0 deletions
Show diff stats
gologger.go
... | ... | @@ -5,6 +5,7 @@ import ( |
5 | 5 | "os" |
6 | 6 | "sync" |
7 | 7 | "time" |
8 | + "runtime" | |
8 | 9 | ) |
9 | 10 | |
10 | 11 | var muEv = &sync.Mutex{} |
... | ... | @@ -142,3 +143,31 @@ func (l *Logger) LogError(comment string, err error) { |
142 | 143 | l.errorf.WriteString(time.Now().Format(time.RFC3339) + ": " + comment + ": " + err.Error() + "\n") |
143 | 144 | l.splitErrorLog() |
144 | 145 | } |
146 | + | |
147 | +func (l *Logger) LogDetailedEvent(event string) { | |
148 | + muEv.Lock() | |
149 | + defer muEv.Unlock() | |
150 | + _, file, line, ok := runtime.Caller(1) | |
151 | + var s string | |
152 | + if ok { | |
153 | + s = fmt.Sprintf("%s: %s %d: %s\n", time.Now().Format(time.RFC3339), file, line, event) | |
154 | + } else { | |
155 | + s = fmt.Sprintf(time.Now().Format(time.RFC3339) + ": [can't retreive stack details]:" + event + "\n") | |
156 | + } | |
157 | + l.eventf.WriteString(s) | |
158 | + l.splitEventLog() | |
159 | +} | |
160 | + | |
161 | +func (l *Logger) LogDetailedError(err error) { | |
162 | + muEr.Lock() | |
163 | + defer muEr.Unlock() | |
164 | + _, file, line, ok := runtime.Caller(1) | |
165 | + var s string | |
166 | + if ok { | |
167 | + s = fmt.Sprintf("%s %s %d: %s\n", time.Now().Format(time.RFC3339), file, line, err.Error()) | |
168 | + } else { | |
169 | + s = fmt.Sprintf(time.Now().Format(time.RFC3339) + ": [can't retreive stack details]:" + err.Error() + "\n") | |
170 | + } | |
171 | + l.errorf.WriteString(s) | |
172 | + l.splitErrorLog() | |
173 | +} | ... | ... |