tlog: switch default logger to syslog
...unless "-nosyslog" is passed. All gocryptfs messages already go to syslog, but the messages that the go-fuse lib emits were still printed to stdout. Fixes issue #13 ( https://github.com/rfjakob/gocryptfs/issues/13 )
This commit is contained in:
parent
a8a0d2d92c
commit
547ddf4264
@ -8,5 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) {
|
||||
Debug.Printf("Cannot switch to syslog - need Go 1.5 or higher")
|
||||
Info.Printf("Cannot switch to syslog - need Go 1.5 or higher")
|
||||
}
|
||||
|
||||
func SwitchLoggerToSyslog(p syslog.Priority) {
|
||||
Info.Printf("Cannot switch to syslog - need Go 1.5 or higher")
|
||||
}
|
||||
|
@ -4,14 +4,26 @@
|
||||
package tlog
|
||||
|
||||
import (
|
||||
"log"
|
||||
"log/syslog"
|
||||
)
|
||||
|
||||
func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) {
|
||||
w, err := syslog.New(p, ProgramName)
|
||||
if err != nil {
|
||||
Warn.Printf("Cannot switch 0x%02x to syslog: %v", p, err)
|
||||
Warn.Printf("SwitchToSyslog: %v", err)
|
||||
} else {
|
||||
l.SetOutput(w)
|
||||
}
|
||||
}
|
||||
|
||||
// SwitchLoggerToSyslog redirects the default log.Logger that the go-fuse lib uses
|
||||
// to syslog.
|
||||
func SwitchLoggerToSyslog(p syslog.Priority) {
|
||||
w, err := syslog.New(p, ProgramName)
|
||||
if err != nil {
|
||||
Warn.Printf("SwitchLoggerToSyslog: %v", err)
|
||||
} else {
|
||||
log.SetOutput(w)
|
||||
}
|
||||
}
|
||||
|
1
main.go
1
main.go
@ -347,6 +347,7 @@ func main() {
|
||||
tlog.Info.SwitchToSyslog(syslog.LOG_USER | syslog.LOG_INFO)
|
||||
tlog.Debug.SwitchToSyslog(syslog.LOG_USER | syslog.LOG_DEBUG)
|
||||
tlog.Warn.SwitchToSyslog(syslog.LOG_USER | syslog.LOG_WARNING)
|
||||
tlog.SwitchLoggerToSyslog(syslog.LOG_USER | syslog.LOG_WARNING)
|
||||
}
|
||||
}
|
||||
// Wait for SIGINT in the background and unmount ourselves if we get it.
|
||||
|
Loading…
Reference in New Issue
Block a user