diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-08 14:53:18 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-08 14:53:18 +0900 |
commit | e7ebdd8e244dac3c742e3e062d4a55768ecf8433 (patch) | |
tree | 1feea0e4b95e97a50cd249e58c08d508ab97117c /bgpd.go | |
parent | 8d6dd03eb52d250790959e2d23d68531d6b056a8 (diff) |
bgpd: support syslogd (-s/--syslog) option
- Local syslogd via unix domain socket:
"-s unix"
- Remote syslogd via tcp/udp
"-s tcp:10.0.0.1:514
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'bgpd.go')
-rw-r--r-- | bgpd.go | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -17,14 +17,18 @@ package main import ( log "github.com/Sirupsen/logrus" + "github.com/Sirupsen/logrus/hooks/syslog" "github.com/jessevdk/go-flags" "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet" "github.com/osrg/gobgp/server" + "io/ioutil" + "log/syslog" "os" "os/signal" "runtime" + "strings" "syscall" ) @@ -38,6 +42,7 @@ func main() { ConfigFile string `short:"f" long:"config-file" description:"specifying a config file"` LogLevel string `short:"l" long:"log-level" description:"specifying log level"` LogJson bool `short:"j" long:"log-json" description:"use json format for logging"` + UseSyslog string `short:"s" long:"syslog" description:"use syslogd"` } _, err := flags.Parse(&opts) if err != nil { @@ -52,7 +57,27 @@ func main() { default: log.SetLevel(log.InfoLevel) } - log.SetOutput(os.Stderr) + + if opts.UseSyslog == "" { + log.SetOutput(os.Stderr) + } else { + dst := strings.SplitN(opts.UseSyslog, ":", 2) + network := "" + addr := "" + if len(dst) == 2 { + network = dst[0] + addr = dst[1] + } + hook, err := logrus_syslog.NewSyslogHook(network, addr, syslog.LOG_INFO, "bgpd") + if err != nil { + log.Error("Unable to connect to syslog daemon, ", opts.UseSyslog) + os.Exit(1) + } else { + log.AddHook(hook) + log.SetOutput(ioutil.Discard) + } + } + if opts.LogJson { log.SetFormatter(&log.JSONFormatter{}) } |