diff options
author | Jakob Unterwurzacher | 2016-06-26 23:30:22 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-06-26 23:30:22 +0200 |
commit | 547ddf42648e55b3235343ac7d4eae27931362f8 (patch) | |
tree | dab115a13447594f267f6cbb56aace0d79df84ad | |
parent | a8a0d2d92c2ea98040e144c1a0d1fee4dd4b9d1d (diff) |
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 )
-rw-r--r-- | internal/tlog/log_go1.4.go | 6 | ||||
-rw-r--r-- | internal/tlog/log_go1.5.go | 14 | ||||
-rw-r--r-- | main.go | 1 |
3 files changed, 19 insertions, 2 deletions
diff --git a/internal/tlog/log_go1.4.go b/internal/tlog/log_go1.4.go index fae0e9b..98d69db 100644 --- a/internal/tlog/log_go1.4.go +++ b/internal/tlog/log_go1.4.go @@ -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") } diff --git a/internal/tlog/log_go1.5.go b/internal/tlog/log_go1.5.go index 755f623..40ec656 100644 --- a/internal/tlog/log_go1.5.go +++ b/internal/tlog/log_go1.5.go @@ -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) + } +} @@ -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. |