Skip to content

Commit fe42699

Browse files
author
Matthew Fisher
committed
feat(logger): expose log-addr and log-port as flags
1 parent 97108d0 commit fe42699

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

logger/main.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
56
"log"
67
"os"
78
"os/signal"
9+
"strconv"
810
"syscall"
911
"time"
1012

@@ -13,18 +15,22 @@ import (
1315
)
1416

1517
var (
16-
enablePublish bool
17-
publishHost string
18-
publishPath string
19-
publishPort string
18+
logAddr string
19+
logPort int
20+
enablePublish bool
21+
publishHost string
22+
publishPath string
23+
publishPort string
2024
publishInterval int
2125
publishTTL int
2226
)
2327

2428
func init() {
29+
flag.StringVar(&logAddr, "log-addr", "0.0.0.0", "bind address for the logger")
30+
flag.IntVar(&logPort, "log-port", 514, "bind port for the logger")
2531
flag.BoolVar(&enablePublish, "publish", false, "enable publishing to service discovery")
26-
flag.IntVar(&publishInterval, "publish-interval", 10, "publish interval in seconds")
2732
flag.StringVar(&publishHost, "publish-host", getopt("HOST", "127.0.0.1"), "service discovery hostname")
33+
flag.IntVar(&publishInterval, "publish-interval", 10, "publish interval in seconds")
2834
flag.StringVar(&publishPath, "publish-path", getopt("ETCD_PATH", "/deis/logs"), "path to publish host/port information")
2935
flag.StringVar(&publishPort, "publish-port", getopt("ETCD_PORT", "4001"), "service discovery port")
3036
flag.IntVar(&publishTTL, "publish-ttl", publishInterval*2, "publish TTL in seconds")
@@ -33,29 +39,27 @@ func init() {
3339
func main() {
3440
flag.Parse()
3541

36-
externalPort := getopt("EXTERNAL_PORT", "514")
37-
3842
client := etcd.NewClient([]string{"http://" + publishHost + ":" + publishPort})
3943

4044
// Wait for terminating signal
4145
exitChan := make(chan os.Signal, 2)
4246
cleanupChan := make(chan bool)
4347
signal.Notify(exitChan, syscall.SIGTERM, syscall.SIGINT)
4448

45-
go syslogd.Listen(exitChan, cleanupChan)
49+
go syslogd.Listen(exitChan, cleanupChan, fmt.Sprintf("%s:%d", logAddr, logPort))
4650

4751
if enablePublish {
48-
go publishService(client, publishHost, publishPath, externalPort, uint64(time.Duration(publishTTL).Seconds()))
52+
go publishService(client, publishHost, publishPath, strconv.Itoa(logPort), uint64(time.Duration(publishTTL).Seconds()))
4953
}
5054

5155
// Wait for the proper shutdown of the syslog server before exit
5256
<-cleanupChan
5357
}
5458

55-
func publishService(client *etcd.Client, host string, etcdPath string, externalPort string, ttl uint64) {
59+
func publishService(client *etcd.Client, host string, etcdPath string, port string, ttl uint64) {
5660
for {
5761
setEtcd(client, etcdPath+"/host", host, ttl)
58-
setEtcd(client, etcdPath+"/port", externalPort, ttl)
62+
setEtcd(client, etcdPath+"/port", port, ttl)
5963
time.Sleep(time.Duration(publishInterval))
6064
}
6165
}

logger/syslogd/syslogd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (h *handler) mainLoop() {
9797
}
9898

9999
// Listen starts a new syslog server which runs until it receives a signal.
100-
func Listen(signalChan chan os.Signal, cleanupDone chan bool) {
100+
func Listen(signalChan chan os.Signal, cleanupDone chan bool, bindAddr string) {
101101
fmt.Println("Starting syslog...")
102102
// If logRoot doesn't exist, create it
103103
// equivalent to Python's `if not os.path.exists(filename)`
@@ -109,7 +109,7 @@ func Listen(signalChan chan os.Signal, cleanupDone chan bool) {
109109
// Create a server with one handler and run one listen gorutine
110110
s := syslog.NewServer()
111111
s.AddHandler(newHandler())
112-
s.Listen("0.0.0.0:514")
112+
s.Listen(bindAddr)
113113
fmt.Println("Syslog server started...")
114114
fmt.Println("deis-logger running")
115115

0 commit comments

Comments
 (0)