From d6cb62252c5a34855fc29d09d75de81ae7c1330f Mon Sep 17 00:00:00 2001 From: Scott Weiss Date: Mon, 23 May 2016 15:01:29 -0400 Subject: [PATCH] fix log file issues fixes #32 Signed-off-by: Scott Weiss --- cmd/daemon.go | 21 +++++++++++---------- pkg/util/log.go | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/daemon.go b/cmd/daemon.go index 54ee21d6..13d636ea 100644 --- a/cmd/daemon.go +++ b/cmd/daemon.go @@ -45,6 +45,15 @@ Example usage: if err := readDaemonConfig(); err != nil { return err } + //don't print vsphere password + redactions := []string{} + for _, vsphereConfig := range daemonConfig.Providers.Vsphere { + redactions = append(redactions, vsphereConfig.VspherePassword, url.QueryEscape(vsphereConfig.VspherePassword)) + } + logrus.SetFormatter(&unikutil.RedactedTextFormatter{ + Redactions: redactions, + }) + if debugMode { logrus.SetLevel(logrus.DebugLevel) } @@ -52,22 +61,14 @@ Example usage: logrus.AddHook(&unikutil.AddTraceHook{true}) } if logFile != "" { - f, err := os.Open(logFile) + os.Create(logFile) + f, err := os.OpenFile(logFile, os.O_WRONLY | os.O_CREATE | os.O_TRUNC, 0777) if err != nil { return errors.New(fmt.Sprintf("failed to open log file %s for writing", logFile), err) } logrus.AddHook(&unikutil.TeeHook{f}) } - //don't print vsphere password - redactions := []string{} - for _, vsphereConfig := range daemonConfig.Providers.Vsphere { - redactions = append(redactions, vsphereConfig.VspherePassword, url.QueryEscape(vsphereConfig.VspherePassword)) - } - logrus.SetFormatter(&unikutil.RedactedTextFormatter{ - Redactions: redactions, - }) - logrus.WithField("config", daemonConfig).Info("daemon started") d, err := daemon.NewUnikDaemon(daemonConfig) if err != nil { diff --git a/pkg/util/log.go b/pkg/util/log.go index 9ef13a30..037fa60f 100644 --- a/pkg/util/log.go +++ b/pkg/util/log.go @@ -125,7 +125,7 @@ func (h *TeeHook) Fire(entry *logrus.Entry) error { logger.WithFields(entry.Data).Info(entry.Message) break case logrus.DebugLevel: - logger.WithFields(entry.Data).Debug(entry.Message) + logger.WithFields(entry.Data).Info(entry.Message) break } return nil