forked from cloudfoundry-community/firehose-to-syslog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 1.14 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
package main
import (
"crypto/tls"
"fmt"
"os"
"github.com/cloudfoundry/noaa"
"github.com/cloudfoundry/noaa/events"
)
var DopplerAddress = "wss://doppler.10.244.0.34.xip.io:443"
var appGuid = os.Getenv("APP_GUID")
var authToken = os.Getenv("CF_ACCESS_TOKEN")
func main() {
connection := noaa.NewConsumer(DopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
connection.SetDebugPrinter(ConsoleDebugPrinter{})
messages, err := connection.RecentLogs(appGuid, authToken)
if err != nil {
fmt.Printf("===== Error getting recent messages: %v\n", err)
} else {
fmt.Println("===== Recent logs")
for _, msg := range messages {
fmt.Println(msg)
}
}
fmt.Println("===== Streaming metrics")
msgChan := make(chan *events.Envelope)
go func() {
defer close(msgChan)
errorChan := make(chan error)
go connection.Stream(appGuid, authToken, msgChan, errorChan, nil)
for err := range errorChan {
fmt.Fprintf(os.Stderr, "%v\n", err.Error())
}
}()
for msg := range msgChan {
fmt.Printf("%v \n", msg)
}
}
type ConsoleDebugPrinter struct{}
func (c ConsoleDebugPrinter) Print(title, dump string) {
println(title)
println(dump)
}