Skip to content

Commit

Permalink
feat(client): send logs to syslog
Browse files Browse the repository at this point in the history
closes #2255
  • Loading branch information
mrl5 committed Jul 11, 2024
1 parent e8c2faf commit 45a77d5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package util

import (
"io"
"log/syslog"
"os"
"path/filepath"
"slices"

log "github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
"gopkg.in/natefinch/lumberjack.v2"

"github.com/netbirdio/netbird/formatter"
Expand All @@ -18,8 +21,9 @@ func InitLog(logLevel string, logPath string) error {
log.Errorf("Failed parsing log-level %s: %s", logLevel, err)
return err
}
custom_outputs := []string{"console", "syslog"};

if logPath != "" && logPath != "console" {
if logPath != "" && !slices.Contains(custom_outputs, logPath) {
lumberjackLogger := &lumberjack.Logger{
// Log file absolute path, os agnostic
Filename: filepath.ToSlash(logPath),
Expand All @@ -29,6 +33,13 @@ func InitLog(logLevel string, logPath string) error {
Compress: true,
}
log.SetOutput(io.Writer(lumberjackLogger))
} else if logPath == "syslog" {
hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")

if err != nil {
log.Errorf("Failed creating syslog hook: %s", err)
}
log.AddHook(hook)
}

if os.Getenv("NB_LOG_FORMAT") == "json" {
Expand Down

0 comments on commit 45a77d5

Please sign in to comment.