Skip to content

Commit

Permalink
Adds logging to syslog
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Broer committed Oct 16, 2015
1 parent 79677bf commit 037fcd2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main // import "github.com/janeczku/go-dnsmasq"

import (
"fmt"
"log/syslog"
"net"
"os"
"os/signal"
Expand All @@ -14,6 +15,7 @@ import (
"syscall"

log "github.com/Sirupsen/logrus"
logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog"
"github.com/codegangsta/cli"
"github.com/miekg/dns"

Expand Down Expand Up @@ -126,6 +128,11 @@ func main() {
Usage: "enable verbose logging",
EnvVar: "DNSMASQ_VERBOSE",
},
cli.BoolFlag{
Name: "syslog",
Usage: "enable syslog logging",
EnvVar: "DNSMASQ_SYSLOG",
},
}
app.Action = func(c *cli.Context) {
exitReason := make(chan error)
Expand All @@ -141,6 +148,15 @@ func main() {
log.SetLevel(log.DebugLevel)
}

if c.Bool("syslog") {
hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_LOCAL0|syslog.LOG_INFO, "go-dnsmasq")
if err != nil {
log.Error("Unable to connect to local syslog daemon")
} else {
log.AddHook(hook)
}
}

if ns := c.String("nameservers"); ns != "" {
for _, hostPort := range strings.Split(ns, ",") {
if !strings.Contains(hostPort, ":") {
Expand Down

0 comments on commit 037fcd2

Please sign in to comment.