mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-07 08:44:07 +01:00
feat(client): send logs to syslog (#2259)
This commit is contained in:
parent
12ff93ba72
commit
1d6f5482dd
@ -121,7 +121,7 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&serviceName, "service", "s", defaultServiceName, "Netbird system service name")
|
||||
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", defaultConfigPath, "Netbird config file location")
|
||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "info", "sets Netbird log level")
|
||||
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Netbird log path. If console is specified the log will be output to stdout")
|
||||
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Netbird log path. If console is specified the log will be output to stdout. If syslog is specified the log will be sent to syslog daemon.")
|
||||
rootCmd.PersistentFlags().StringVarP(&setupKey, "setup-key", "k", "", "Setup key obtained from the Management Service Dashboard (used to register peer)")
|
||||
rootCmd.PersistentFlags().StringVar(&preSharedKey, preSharedKeyFlag, "", "Sets Wireguard PreSharedKey property. If set, then only peers that have the same key can communicate.")
|
||||
rootCmd.PersistentFlags().StringVarP(&hostName, "hostname", "n", "", "Sets a custom hostname for the device")
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
@ -18,8 +19,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),
|
||||
@ -29,6 +31,8 @@ func InitLog(logLevel string, logPath string) error {
|
||||
Compress: true,
|
||||
}
|
||||
log.SetOutput(io.Writer(lumberjackLogger))
|
||||
} else if logPath == "syslog" {
|
||||
AddSyslogHook()
|
||||
}
|
||||
|
||||
if os.Getenv("NB_LOG_FORMAT") == "json" {
|
||||
|
20
util/syslog_nonwindows.go
Normal file
20
util/syslog_nonwindows.go
Normal file
@ -0,0 +1,20 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"log/syslog"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
|
||||
)
|
||||
|
||||
func AddSyslogHook() {
|
||||
hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Failed creating syslog hook: %s", err)
|
||||
}
|
||||
log.AddHook(hook)
|
||||
}
|
3
util/syslog_windows.go
Normal file
3
util/syslog_windows.go
Normal file
@ -0,0 +1,3 @@
|
||||
package util
|
||||
|
||||
func AddSyslogHook() {}
|
Loading…
Reference in New Issue
Block a user