forked from mirror/logrus
logger.ReplaceHooks
This commit is contained in:
parent
fc587f31c8
commit
7a0120e2c6
|
@ -336,3 +336,9 @@ func (logger *Logger) AddHook(hook Hook) {
|
|||
defer logger.mu.Unlock()
|
||||
logger.Hooks.Add(hook)
|
||||
}
|
||||
|
||||
func (logger *Logger) ReplaceHooks(hooks LevelHooks) {
|
||||
logger.mu.Lock()
|
||||
logger.Hooks = hooks
|
||||
logger.mu.Unlock()
|
||||
}
|
||||
|
|
|
@ -421,6 +421,22 @@ func TestLoggingRaceWithHooksOnEntry(t *testing.T) {
|
|||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestHooksReplace(t *testing.T) {
|
||||
old, cur := &TestHook{}, &TestHook{}
|
||||
|
||||
logger := New()
|
||||
logger.AddHook(old)
|
||||
|
||||
hooks := make(LevelHooks)
|
||||
hooks.Add(cur)
|
||||
logger.ReplaceHooks(hooks)
|
||||
|
||||
logger.Info("test")
|
||||
|
||||
assert.Equal(t, old.Fired, false)
|
||||
assert.Equal(t, cur.Fired, true)
|
||||
}
|
||||
|
||||
// Compile test
|
||||
func TestLogrusInterface(t *testing.T) {
|
||||
var buffer bytes.Buffer
|
||||
|
|
Loading…
Reference in New Issue