Make fireHooks() method receive a copy of Entry structure to avoid race conditions

Signed-off-by: Jay Ching Lim <imjching@users.noreply.github.com>
This commit is contained in:
Jay Ching Lim
2018-02-12 17:26:48 -05:00
parent 9f91ab2ef9
commit be569094e9
2 changed files with 28 additions and 4 deletions
+4 -2
View File
@@ -113,10 +113,12 @@ func (entry Entry) log(level Level, msg string) {
}
}
func (entry *Entry) fireHooks() {
// This function is not declared with a pointer value because otherwise
// race conditions will occur when using multiple goroutines
func (entry Entry) fireHooks() {
entry.Logger.mu.Lock()
defer entry.Logger.mu.Unlock()
err := entry.Logger.Hooks.Fire(entry.Level, entry)
err := entry.Logger.Hooks.Fire(entry.Level, &entry)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err)
}