-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
68 lines (61 loc) · 1.38 KB
/
init.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
package logger
import (
"log"
)
var internalLogger *Logger
// NewObject ...
func NewObject(message string, HTTPCode int) InformationConstruct {
return InformationConstruct{
Message: message,
HTTPCode: HTTPCode,
Temporary: false,
ReturnToClient: false,
}
}
func NewDBRInterface(logtag string, showTiming, showErrors, showInfo, addToChain bool, opID string) DBREventReceiver {
return DBREventReceiver{
LogTag: logtag,
ShowInfo: showInfo,
ShowErrors: showErrors,
ShowTiming: showTiming,
AddToChain: addToChain,
OPID: opID,
}
}
// Init ...
// This method gives you a new logging client
func Init(config *LoggingConfig) (err error, l *Logger) {
l = &Logger{}
if config.Type == "google" {
if config.ProjectID == "" {
return NewObject("You need to set a projectID", 0), nil
}
}
if config.DefaultLogTag == "" {
return NewObject("You need to set a default log tag", 0), nil
}
l.Config = config
switch config.Type {
case "google":
client := GoogleClient{}
err = client.new(config)
l.Client = &client
if err != nil {
panic(err)
}
break
case "stdout":
client := StdClient{}
err = client.new(config)
l.Client = &client
case "aws":
log.Println("todo ...")
default:
client := StdClient{}
err = client.new(config)
l.Client = &client
}
l.Chain = make(map[string][]InformationConstruct)
internalLogger = l
return
}