Skip to content

Commit

Permalink
add the possibility to send logs to loghost
Browse files Browse the repository at this point in the history
  • Loading branch information
nbosansky committed Jun 10, 2019
1 parent 8d033e5 commit eabb070
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions overlord.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"io"
"log"
"log/syslog"
"os"
"os/exec"
"sort"
Expand Down Expand Up @@ -393,12 +395,35 @@ func iterate() {
}

func main() {
var syslogCfg = os.Getenv("SYSLOG_ADDRESS")
if len(syslogCfg) > 0 {
logWriter, err := syslog.Dial("udp", syslogCfg, syslog.LOG_LOCAL0|syslog.LOG_ERR, "av-balancing")
if err != nil {
panic(err)
}
log.SetOutput(doubleWriter{logWriter, os.Stdout})
}

for {
iterate()
time.Sleep(time.Duration(interval) * time.Second)
}
}

// write to two io.Writer
type doubleWriter struct {
a, b io.Writer
}

func (dw doubleWriter) Write(p []byte) (int, error) {
n, err := dw.a.Write(p)
if err != nil {
return n, err
}
n, err = dw.b.Write(p)
return n, err
}

// func main() {
// for {
// log.Println(lookupIPs("qa-site-survey-instance"))
Expand Down

0 comments on commit eabb070

Please sign in to comment.