-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
91 lines (74 loc) · 1.81 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
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
package main
import (
"flag"
"io"
"os"
"strings"
"code.cyb3r.social/skat/goDataCollector/app"
log "github.com/sirupsen/logrus"
)
func setupLog(logFilePath string) {
logFile, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
log.WithError(err).Errorf("Failed to create logfile %s\n", logFilePath)
} else {
multi := io.MultiWriter(logFile, os.Stdout)
log.SetOutput(multi)
}
log.SetFormatter(&log.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05",
PadLevelText: true,
})
}
func exit() {
log.Infof("exit\n")
}
func main() {
defer exit()
var lLevel string
var daemon bool
var help bool
var logToFile bool
var devLocal bool
flag.StringVar(&lLevel, "l", "Info", "default (Info) possibel values are Info, Debug, Trace")
flag.BoolVar(&daemon, "d", false, "run as daemon")
flag.BoolVar(&help, "h", false, "print help")
flag.BoolVar(&logToFile, "f", false, "log to file")
flag.BoolVar(&devLocal, "dl", false, "load local.config.json")
flag.Parse()
if help {
flag.PrintDefaults()
os.Exit(0)
}
log.SetOutput(os.Stdout)
log.SetFormatter(&log.TextFormatter{
ForceColors: true,
DisableColors: false,
TimestampFormat: "2006-01-02 15:04:05",
PadLevelText: true,
})
switch strings.ToLower(lLevel) {
case "info":
log.SetLevel(log.InfoLevel)
log.Infof("Loglevel set to Info.")
case "trace":
log.SetLevel(log.TraceLevel)
log.SetReportCaller(true)
log.Infof("Loglevel set to Trace.")
case "debug":
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
log.Infof("Loglevel set to Debug.")
default:
log.SetLevel(log.InfoLevel)
log.Warningf("Provided loglevel %s not valid using Info.\n", lLevel)
}
if logToFile {
setupLog("./appData/Logs/today.log")
}
if daemon {
app.Daemonize(devLocal)
} else {
app.Run(devLocal)
}
}