forked from yeabow/cat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cat.go
62 lines (50 loc) · 1.04 KB
/
cat.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
package cat
import (
"os"
"sync/atomic"
)
var isEnabled uint32 = 0
func Init(domain string) {
InitWithLocation(domain, "")
}
func InitWithLocation(domain, location string) {
if err := config.Init(domain, location); err != nil {
logger.Warning("Cat initialize failed.")
return
}
enable()
go background(&router)
go background(&monitor)
go background(&sender)
aggregator.Background()
}
func InitWithConfig(domain string, cfg XMLConfig) {
if err := config.InitWithConfig(domain, cfg); err != nil {
logger.Warning("Cat initialize failed.")
return
}
enable()
go background(&router)
go background(&monitor)
go background(&sender)
aggregator.Background()
}
func enable() {
if atomic.SwapUint32(&isEnabled, 1) == 0 {
logger.Info("Cat has been enabled.")
}
}
func disable() {
if atomic.SwapUint32(&isEnabled, 0) == 1 {
logger.Info("Cat has been disabled.")
}
}
func IsEnabled() bool {
return atomic.LoadUint32(&isEnabled) > 0
}
func Shutdown() {
scheduler.shutdown()
}
func DebugOn() {
logger.logger.SetOutput(os.Stdout)
}