-
Notifications
You must be signed in to change notification settings - Fork 25
/
setup.go
73 lines (63 loc) · 1.63 KB
/
setup.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
package main
import (
"os"
"github.com/getsentry/sentry-go"
"github.com/rawnly/splash-cli/config"
"github.com/rawnly/splash-cli/lib/analytics"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// Setup the logs
func setupLogs() {
// You could set this to any `io.Writer` such as a file
file, err := os.OpenFile("splash-cli.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err == nil {
logrus.SetOutput(file)
} else {
logrus.Warn("Failed to log to file, using default stderr")
}
if config.GetFormatterType() == config.LOG_FORMAT_JSON {
logrus.SetFormatter(&logrus.JSONFormatter{
TimestampFormat: "2006-01-02 15:04:05",
DisableTimestamp: true,
})
} else {
logrus.SetFormatter(&logrus.TextFormatter{
DisableColors: false,
FullTimestamp: true,
DisableTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
}
if config.IsDebug() {
if os.Getenv("LOG_LEVEL") == "trace" {
logrus.SetLevel(logrus.TraceLevel)
} else {
logrus.SetLevel(logrus.DebugLevel)
}
logrus.SetReportCaller(true)
} else {
logrus.SetLevel(logrus.WarnLevel)
}
}
// Setup sentry if not in DEBUG mode
func setupSentry() {
if !config.IsSentryEnabled() {
logrus.WithFields(logrus.Fields{
"dsn": config.SentryDSN,
"debug": config.IsDebug(),
}).Trace("Sentry disabled")
return
}
err := sentry.Init(sentry.ClientOptions{
Dsn: config.SentryDSN,
TracesSampleRate: 1.0,
Environment: config.GetEnvironment(),
Debug: config.SentryDebug == "true",
})
cobra.CheckErr(err)
}
// Setup posthog
func setupPosthog() *analytics.Analytics {
return analytics.New(config.PostHogKey)
}