-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (53 loc) · 1.5 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
package main
import (
"fmt"
"os"
"time"
"net/http"
_ "net/http/pprof"
coralogix "github.com/coralogix/go-coralogix-sdk"
logrus "github.com/sirupsen/logrus"
)
func attachCoralogixHook(log *logrus.Logger, privateKey, applicationKey, subsystemKey string) {
CoralogixHook := coralogix.NewCoralogixHook(
privateKey, applicationKey, subsystemKey,
)
// defer CoralogixHook.Close() // No need to close in our case
log.AddHook(CoralogixHook)
}
func runLogs(log *logrus.Logger) {
ticker := time.NewTicker(1 * time.Second)
for range ticker.C {
log.WithFields(logrus.Fields{
"hello": "world",
"verisonDate": time.Now(),
}).Info("Hello World Message")
}
}
func newLogger() *logrus.Logger {
var log = logrus.New()
log.SetFormatter(&logrus.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(logrus.DebugLevel)
return log
}
func runProfiler() {
go func() {
fmt.Println(http.ListenAndServe("localhost:6060", nil))
}()
}
func main() {
runProfiler()
log := newLogger()
privateKey, applicationKey, subsystemKey :=
os.Getenv("CORALOGIX_PRIVATE_KEY"),
os.Getenv("CORALOGIX_APPLICATION_NAME"),
os.Getenv("CORALOGIX_SUBSYSTEM_NAME")
if privateKey == "" || applicationKey == "" || subsystemKey == "" {
panic("Please specificy env vars: CORALOGIX_PRIVATE_KEY, CORALOGIX_APPLICATION_NAME, CORALOGIX_SUBSYSTEM_NAME")
}
// COMMENT THE NEXT LINE OUT - and see cpu difference
attachCoralogixHook(log, privateKey, applicationKey, subsystemKey)
go runLogs(log)
<-time.After(2 * time.Minute)
}