-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathglobal.go
More file actions
93 lines (77 loc) · 2.4 KB
/
global.go
File metadata and controls
93 lines (77 loc) · 2.4 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package dotlog
import (
"fmt"
"github.com/devfeel/dotlog/config"
"github.com/devfeel/dotlog/internal"
"github.com/devfeel/dotlog/layout"
"github.com/devfeel/dotlog/targets"
"github.com/devfeel/dotlog/const"
)
var (
GlobalTargetMap map[string]targets.Target
GlobalVariable *layout.Variable
GlobalLoggerMap map[string]Logger
)
func init() {
GlobalTargetMap = make(map[string]targets.Target)
GlobalVariable = layout.GetVariable()
GlobalLoggerMap = make(map[string]Logger)
}
func StartLogService(configFile string) error {
conf, err := config.InitConfig(configFile)
if err != nil {
fmt.Println(err)
return err
}
config.GlobalAppConfig = conf
//init innerlogger
internal.InitInnerLogger(conf.Global.InnerLogPath, conf.Global.InnerLogEncode)
internal.GlobalInnerLogger.Debug("*******************New Begin***********************")
internal.GlobalInnerLogger.Debug("devfeel.dotlog ["+ _const.Version+"] InitConfig success")
//init variable
for _, v := range conf.Variables {
GlobalVariable.RegisterUserVar(v.Name, v.Value)
}
internal.GlobalInnerLogger.Debug("RegisterUserVar success - total:", len(GlobalVariable.UserVar))
//init file target
var count int
for _, v := range conf.Targets.FileTargets {
GlobalTargetMap[v.Name] = targets.NewFileTarget(v)
count++
}
internal.GlobalInnerLogger.Debug("InitFileTargets success - total:", count)
//init udp target
count = 0
for _, v := range conf.Targets.UdpTargets {
GlobalTargetMap[v.Name] = targets.NewUdpTarget(v)
count++
}
internal.GlobalInnerLogger.Debug("InitUdpTargets success - total:", count)
//init http target
count = 0
for _, v := range conf.Targets.HttpTargets {
GlobalTargetMap[v.Name] = targets.NewHttpTarget(v)
count++
}
internal.GlobalInnerLogger.Debug("InitHttpTargets success - total:", count)
//init email target
count = 0
for _, v := range conf.Targets.EMailTargets {
GlobalTargetMap[v.Name] = targets.NewEMailTarget(v)
count++
}
internal.GlobalInnerLogger.Debug("InitEMailTargets success - total:", count)
//init fmt target
count = 0
for _, v := range conf.Targets.FmtTargets {
GlobalTargetMap[v.Name] = targets.NewFmtTarget(v)
count++
}
internal.GlobalInnerLogger.Debug("InitFmtTargets success - total:", count)
//init logger
for _, v := range conf.Loggers {
GlobalLoggerMap[v.Name] = NewLogger(v)
}
internal.GlobalInnerLogger.Debug("InitLogger success - total:", len(GlobalLoggerMap))
return nil
}