Skip to content

Commit

Permalink
Exclude syslog from windows targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Jan 27, 2020
1 parent 5c55c95 commit c2909aa
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 34 deletions.
34 changes: 0 additions & 34 deletions cmd/chirpstack-gateway-bridge/cmd/root_run.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package cmd

import (
"log/syslog"
"os"
"os/signal"
"syscall"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
lsyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/spf13/cobra"

"github.com/brocaar/chirpstack-gateway-bridge/internal/backend"
Expand Down Expand Up @@ -55,38 +53,6 @@ func setLogLevel() error {
return nil
}

func setSyslog() error {
if !config.C.General.LogToSyslog {
return nil
}

var prio syslog.Priority

switch log.StandardLogger().Level {
case log.DebugLevel:
prio = syslog.LOG_USER | syslog.LOG_DEBUG
case log.InfoLevel:
prio = syslog.LOG_USER | syslog.LOG_INFO
case log.WarnLevel:
prio = syslog.LOG_USER | syslog.LOG_WARNING
case log.ErrorLevel:
prio = syslog.LOG_USER | syslog.LOG_ERR
case log.FatalLevel:
prio = syslog.LOG_USER | syslog.LOG_CRIT
case log.PanicLevel:
prio = syslog.LOG_USER | syslog.LOG_CRIT
}

hook, err := lsyslog.NewSyslogHook("", "", prio, "chirpstack-gateway-bridge")
if err != nil {
return errors.Wrap(err, "get syslog hook error")
}

log.AddHook(hook)

return nil
}

func printStartMessage() error {
log.WithFields(log.Fields{
"version": version,
Expand Down
44 changes: 44 additions & 0 deletions cmd/chirpstack-gateway-bridge/cmd/root_run_syslog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// +build !windows

package cmd

import (
"log/syslog"

"github.com/brocaar/chirpstack-gateway-bridge/internal/config"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
lsyslog "github.com/sirupsen/logrus/hooks/syslog"
)

func setSyslog() error {
if !config.C.General.LogToSyslog {
return nil
}

var prio syslog.Priority

switch log.StandardLogger().Level {
case log.DebugLevel:
prio = syslog.LOG_USER | syslog.LOG_DEBUG
case log.InfoLevel:
prio = syslog.LOG_USER | syslog.LOG_INFO
case log.WarnLevel:
prio = syslog.LOG_USER | syslog.LOG_WARNING
case log.ErrorLevel:
prio = syslog.LOG_USER | syslog.LOG_ERR
case log.FatalLevel:
prio = syslog.LOG_USER | syslog.LOG_CRIT
case log.PanicLevel:
prio = syslog.LOG_USER | syslog.LOG_CRIT
}

hook, err := lsyslog.NewSyslogHook("", "", prio, "chirpstack-gateway-bridge")
if err != nil {
return errors.Wrap(err, "get syslog hook error")
}

log.AddHook(hook)

return nil
}
16 changes: 16 additions & 0 deletions cmd/chirpstack-gateway-bridge/cmd/root_run_syslog_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build windows

package cmd

import (
"github.com/brocaar/chirpstack-gateway-bridge/internal/config"
log "github.com/sirupsen/logrus"
)

func setSyslog() error {
if config.C.General.LogToSyslog {
log.Fatal("syslog logging is not supported on Windows")
}

return nil
}

0 comments on commit c2909aa

Please sign in to comment.