mirror of https://github.com/sirupsen/logrus.git
Merge branch 'field-logger-with-hooks-race' of git://github.com/thundercat1/logrus into master
This commit is contained in:
commit
c108f5553c
2
entry.go
2
entry.go
|
@ -137,9 +137,9 @@ func (entry *Entry) fireHooks() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) write() {
|
func (entry *Entry) write() {
|
||||||
serialized, err := entry.Logger.Formatter.Format(entry)
|
|
||||||
entry.Logger.mu.Lock()
|
entry.Logger.mu.Lock()
|
||||||
defer entry.Logger.mu.Unlock()
|
defer entry.Logger.mu.Unlock()
|
||||||
|
serialized, err := entry.Logger.Formatter.Format(entry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
|
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -403,6 +403,24 @@ func TestLoggingRace(t *testing.T) {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoggingRaceWithHooksOnEntry(t *testing.T) {
|
||||||
|
logger := New()
|
||||||
|
hook := new(ModifyHook)
|
||||||
|
logger.AddHook(hook)
|
||||||
|
entry := logger.WithField("context", "clue")
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(100)
|
||||||
|
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
go func() {
|
||||||
|
entry.Info("info")
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
// Compile test
|
// Compile test
|
||||||
func TestLogrusInterface(t *testing.T) {
|
func TestLogrusInterface(t *testing.T) {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
Loading…
Reference in New Issue