forked from ResilienceTesting/gremlinproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (58 loc) · 1.56 KB
/
main.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
package main
import (
"flag"
"fmt"
"github.com/ResilienceTesting/gremlinproxy/config"
"github.com/ResilienceTesting/gremlinproxy/router"
"net"
"os"
"github.com/sirupsen/logrus"
)
func main() {
// Read config
cpath := flag.String("c", "", "Path to the config file")
flag.Parse()
if *cpath == "" {
fmt.Println("No config file specified.\nusage: gremlinproxy -c configfile")
os.Exit(1)
}
conf := config.ReadConfig(*cpath)
fmt.Println("Config read successful")
var log = config.GlobalLogger
// Log as JSON instead of the default ASCII formatter.
if conf.LogJSON {
log.Formatter = new(logrus.JSONFormatter)
}
if conf.LogstashHost != "" {
conn, err := net.Dial("udp", conf.LogstashHost)
if err == nil {
config.ProxyLogger.Out = conn
} else {
config.ProxyLogger.Out = os.Stderr
config.ProxyLogger.Warn("Could not establish connection to logstash, logging to stderr")
}
} else { //else console
config.ProxyLogger.Out = os.Stderr
}
// parse and set our log level
if conf.LogLevel != "" {
lvl, err := logrus.ParseLevel(conf.LogLevel)
if err != nil {
// default is info, if something went wrong
log.Level = logrus.InfoLevel
log.Error("Error parsing log level, defaulting to info")
} else {
log.Level = lvl
}
} else {
log.Level = logrus.InfoLevel
}
config.TrackingHeader = conf.Router.TrackingHeader
log.WithField("trackingHeader", config.TrackingHeader).Debug("Config value")
if config.TrackingHeader == "" {
panic("No trackingheader provided")
}
// Start the router
r := router.NewRouter(conf)
r.Run() //this blocks
}