forked from gliderlabs/logspout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logspout.go
73 lines (64 loc) · 1.69 KB
/
logspout.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 (
"fmt"
"log"
"os"
"strings"
"text/tabwriter"
"github.com/gliderlabs/logspout/cfg"
"github.com/gliderlabs/logspout/router"
)
// Version is the running version of logspout
var Version string
func main() {
if len(os.Args) == 2 && os.Args[1] == "--version" {
fmt.Printf("%s\n", Version)
os.Exit(0)
}
log.Printf("# logspout %s by gliderlabs\n", Version)
log.Printf("# adapters: %s\n", strings.Join(router.AdapterFactories.Names(), " "))
log.Printf("# options : ")
if d := cfg.GetEnvDefault("DEBUG", ""); d != "" {
log.Printf("debug:%s\n", d)
}
if b := cfg.GetEnvDefault("BACKLOG", ""); b != "" {
log.Printf("backlog:%s\n", b)
}
log.Printf("persist:%s\n", cfg.GetEnvDefault("ROUTESPATH", "/mnt/routes"))
var jobs []string
for _, job := range router.Jobs.All() {
if err := job.Setup(); err != nil {
log.Printf("!! %v\n", err)
os.Exit(1)
}
if job.Name() != "" {
jobs = append(jobs, job.Name())
}
}
log.Printf("# jobs : %s\n", strings.Join(jobs, " "))
routes, _ := router.Routes.GetAll()
if len(routes) > 0 {
log.Println("# routes :")
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintln(w, "# ADAPTER\tADDRESS\tCONTAINERS\tSOURCES\tOPTIONS") //nolint:errcheck
for _, route := range routes {
fmt.Fprintf(w, "# %s\t%s\t%s\t%s\t%s\n",
route.Adapter,
route.Address,
route.FilterID+route.FilterName+strings.Join(route.FilterLabels, ","),
strings.Join(route.FilterSources, ","),
route.Options)
}
w.Flush()
} else {
log.Println("# routes : none")
}
for _, job := range router.Jobs.All() {
job := job
go func() {
log.Fatalf("%s ended: %s", job.Name(), job.Run())
}()
}
select {}
}