This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
forked from gliderlabs/logspout
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logspout.go
77 lines (67 loc) · 1.56 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
74
75
76
77
package main
import (
"fmt"
"log"
"os"
"strings"
"text/tabwriter"
"github.com/gliderlabs/logspout/router"
)
var Version string
func getopt(name, dfault string) string {
value := os.Getenv(name)
if value == "" {
value = dfault
}
return value
}
func main() {
if len(os.Args) == 2 && os.Args[1] == "--version" {
fmt.Println(Version)
os.Exit(0)
}
fmt.Printf("# logspout %s by gliderlabs\n", Version)
fmt.Printf("# adapters: %s\n", strings.Join(router.AdapterFactories.Names(), " "))
fmt.Printf("# options : ")
if getopt("DEBUG", "") != "" {
fmt.Printf("debug:%s ", getopt("DEBUG", ""))
}
fmt.Printf("persist:%s\n", getopt("ROUTESPATH", "/mnt/routes"))
var jobs []string
for _, job := range router.Jobs.All() {
err := job.Setup()
if err != nil {
fmt.Println("!!", err)
os.Exit(1)
}
if job.Name() != "" {
jobs = append(jobs, job.Name())
}
}
fmt.Printf("# jobs : %s\n", strings.Join(jobs, " "))
routes, _ := router.Routes.GetAll()
if len(routes) > 0 {
fmt.Println("# routes :")
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintln(w, "# ADAPTER\tADDRESS\tCONTAINERS\tSOURCES\tOPTIONS")
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.FilterSources, ","),
route.Options)
}
w.Flush()
} else {
fmt.Println("# routes : none")
}
for _, job := range router.Jobs.All() {
job := job
go func() {
log.Fatalf("%s ended: %s", job.Name(), job.Run())
}()
}
select {}
}