Skip to content

Commit

Permalink
Use MultiWriter to write logs to syslog and console
Browse files Browse the repository at this point in the history
  • Loading branch information
nbosansky committed Jun 11, 2019
1 parent eabb070 commit a25e2df
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions overlord.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ 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")
syslogWriter, err := syslog.Dial("udp", syslogCfg, syslog.LOG_LOCAL0|syslog.LOG_ERR, "av-balancing")
if err != nil {
panic(err)
}
log.SetOutput(doubleWriter{logWriter, os.Stdout})
log.SetOutput(io.MultiWriter(os.Stdout, syslogWriter))
}

for {
Expand All @@ -410,20 +410,6 @@ func main() {
}
}

// 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 a25e2df

Please sign in to comment.