-
Notifications
You must be signed in to change notification settings - Fork 0
/
libreLogger_test.go
70 lines (59 loc) · 1.67 KB
/
libreLogger_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package libreLogger
import (
"fmt"
"testing"
libreConfig "github.com/Spruik/libre-configuration"
"github.com/Spruik/libre-logging/interfaces"
"github.com/Spruik/libre-logging/internal/core/service"
)
func TestInitialize(t *testing.T) {
libreConfig.Initialize("testconfig.json")
Initialize("libreLogger")
logger := GetLogger("DEFAULT")
logger.Debug("configured logger works")
logger = GetLogger("********")
logger.Info("default logger works")
logger = GetLogger("MISSINGNAME")
logger.Info("missing logger works with default")
}
func TestLoggingLevels(t *testing.T) {
logger := GetLogger("DATAGQL")
logger.SetLoggingLevel("DEBUG")
t.Logf("Should see all levels")
writeall(logger)
logger.SetLoggingLevel("INFO")
t.Logf("Should see info+")
writeall(logger)
logger.SetLoggingLevel("WARN")
t.Logf("Should see warn+")
writeall(logger)
logger.SetLoggingLevel("ERROR")
t.Logf("Should see error only")
writeall(logger)
}
func writeall(logger *service.LoggerLocalService) {
logger.Error("error")
logger.Warn("warn")
logger.Info("info")
logger.Debug("debug")
}
type SimpleVisitor struct {
Msg string
}
func (obj *SimpleVisitor) LibreLoggerVisit(logger interfaces.LoggerLocalIF) {
obj.Msg = fmt.Sprintf("visited logger has level = %s and destination = %s", logger.GetLevel(), logger.GetDestination())
}
func TestVisitor(t *testing.T) {
libreConfig.Initialize("testconfig.json")
var v = SimpleVisitor{}
l := GetLogger("DEFAULT")
l.AcceptVisitor(&v)
t.Logf("visiting DEFAULT got: %s", v.Msg)
}
func TestVisitAll(t *testing.T) {
var v = SimpleVisitor{}
for name, logger := range service.LoggerMap {
logger.AcceptVisitor(&v)
t.Logf("visited %s found: %s", name, v.Msg)
}
}