diff --git a/pkg/backy/backy.go b/pkg/backy/backy.go index cffe8bb..9f5d2cd 100644 --- a/pkg/backy/backy.go +++ b/pkg/backy/backy.go @@ -11,6 +11,7 @@ import ( type Host struct { Empty bool Host string + UseSSHAgent bool HostName string Port uint16 PrivateKeyPath string diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go index cbf8663..434d780 100644 --- a/pkg/logging/logging.go +++ b/pkg/logging/logging.go @@ -1,10 +1,44 @@ package logging +import ( + "errors" + "fmt" + "log/syslog" + "os" + + "github.com/spf13/viper" +) + type Logging struct { Err error Output string } -func logger() Logging { - return Logging{} +type Logfile struct { + LogfilePath string +} + +func OpenLogFile(config *viper.Viper) (interface{}, error) { + var logFile *os.File + var syslogWriter *syslog.Writer + var err error + logType := config.GetString("global.logging.type") + if logType != "" { + + switch logType { + case "file": + logFile, err = os.OpenFile(config.GetString("global.logging.file"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) + if err != nil { + return nil, err + } + return logFile, nil + case "syslog": + syslogWriter, err = syslog.New(syslog.LOG_SYSLOG, "Backy") + if err != nil { + return nil, fmt.Errorf("Unable to set logfile: " + err.Error()) + } + return syslogWriter, nil + } + } + return nil, errors.New("log type not specified; Please set global.logging.type in your config file") }