Disable syslog in Go 1.4 and lower (method SetOutput does not exist)

This commit is contained in:
Jakob Unterwurzacher 2016-01-22 21:39:35 +01:00
parent 505fef5a3c
commit df41183e9b
3 changed files with 25 additions and 9 deletions

View File

@ -3,7 +3,6 @@ package cryptfs
import ( import (
"encoding/json" "encoding/json"
"log" "log"
"log/syslog"
"os" "os"
) )
@ -34,14 +33,6 @@ func (l *toggledLogger) Println(v ...interface{}) {
} }
l.Logger.Println(v...) l.Logger.Println(v...)
} }
func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) {
w, err := syslog.New(p, PROGRAM_NAME)
if err != nil {
Warn.Printf("Cannot switch 0x%02x to syslog: %v", p, err)
} else {
l.SetOutput(w)
}
}
// As defined by http://elinux.org/Debugging_by_printing#Log_Levels // As defined by http://elinux.org/Debugging_by_printing#Log_Levels
// Debug messages // Debug messages

8
cryptfs/log_go1.4.go Normal file
View File

@ -0,0 +1,8 @@
// +build !go1.5
// = go 1.4 or lower
package cryptfs
func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) {
Debug.Printf("Cannot switch to syslog - need Go 1.5 or higher")
}

17
cryptfs/log_go1.5.go Normal file
View File

@ -0,0 +1,17 @@
// +build go1.5
// = go 1.5 or higher
package cryptfs
import (
"log/syslog"
)
func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) {
w, err := syslog.New(p, PROGRAM_NAME)
if err != nil {
Warn.Printf("Cannot switch 0x%02x to syslog: %v", p, err)
} else {
l.SetOutput(w)
}
}