added more logging functions and useSSHagent
This commit is contained in:
		@@ -11,6 +11,7 @@ import (
 | 
			
		||||
type Host struct {
 | 
			
		||||
	Empty              bool
 | 
			
		||||
	Host               string
 | 
			
		||||
	UseSSHAgent        bool
 | 
			
		||||
	HostName           string
 | 
			
		||||
	Port               uint16
 | 
			
		||||
	PrivateKeyPath     string
 | 
			
		||||
 
 | 
			
		||||
@@ -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")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user