forked from op/go-logging
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi_test.go
51 lines (40 loc) · 1.21 KB
/
multi_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2013, Örjan Persson. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package logging
import "testing"
func TestMultiLogger(t *testing.T) {
log1 := NewMemoryBackend(8)
log2 := NewMemoryBackend(8)
SetBackend(MultiLogger(log1, log2))
log := MustGetLogger("test")
log.Debug("log")
if "log" != MemoryRecordN(log1, 0).Formatted(0) {
t.Errorf("log1: %v", MemoryRecordN(log1, 0).Formatted(0))
}
if "log" != MemoryRecordN(log2, 0).Formatted(0) {
t.Errorf("log2: %v", MemoryRecordN(log2, 0).Formatted(0))
}
}
func TestMultiLoggerLevel(t *testing.T) {
log1 := NewMemoryBackend(8)
log2 := NewMemoryBackend(8)
leveled1 := AddModuleLevel(log1)
leveled2 := AddModuleLevel(log2)
multi := MultiLogger(leveled1, leveled2)
multi.SetLevel(ERROR, "test")
SetBackend(multi)
log := MustGetLogger("test")
log.Notice("log")
if nil != MemoryRecordN(log1, 0) || nil != MemoryRecordN(log2, 0) {
t.Errorf("unexpected log record")
}
leveled1.SetLevel(DEBUG, "test")
log.Notice("log")
if "log" != MemoryRecordN(log1, 0).Formatted(0) {
t.Errorf("log1 not receieved")
}
if nil != MemoryRecordN(log2, 0) {
t.Errorf("log2 receieved")
}
}