-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
57 lines (48 loc) · 1.23 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
package main
import (
l "log"
"net/http"
_ "net/http/pprof"
"github.com/deis/logger/log"
"github.com/deis/logger/storage"
"github.com/deis/logger/weblog"
)
func main() {
cfg, err := parseConfig(appName)
if err != nil {
l.Fatalf("config error: %s: ", err)
}
storageAdapter, err := storage.NewAdapter(cfg.StorageType, cfg.NumLines)
if err != nil {
l.Fatal("Error creating storage adapter: ", err)
}
storageAdapter.Start()
defer storageAdapter.Stop()
aggregator, err := log.NewAggregator(cfg.AggregatorType, storageAdapter)
if err != nil {
l.Fatal("Error creating log aggregator: ", err)
}
err = aggregator.Listen()
if err != nil {
l.Fatal("Error starting log aggregator: ", err)
}
defer aggregator.Stop()
l.Println("Log aggregator running")
weblogServer := weblog.NewServer(storageAdapter)
weblogServer.Start()
defer weblogServer.Close()
l.Printf("Weblog server serving at %s\n", weblogServer.URL)
// start a Go Profiler
go func() {
l.Println(http.ListenAndServe("0.0.0.0:8099", nil))
}()
stoppedCh := aggregator.Stopped()
select {
case stopErr := <-stoppedCh:
if err != nil {
l.Fatal("Log aggregator has stopped: ", stopErr)
} else {
l.Fatal("Log aggregator has stopped with no error")
}
}
}