summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorKacper BetaƄski <betanski.kacper@gmail.com>2019-01-21 02:51:46 +0100
committerAlex Goodman <wagoodman@users.noreply.github.com>2019-01-20 20:51:46 -0500
commit2301a34403b8e030d81e29a66657f13d25a62780 (patch)
tree77a371625c9e3877f93cffad00162b3877c6221e /cmd
parent54979ae1ebaab7207f2fe6bd65e07266bd54dd76 (diff)
Fix creating log file with logging disabled (#148)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/root.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/cmd/root.go b/cmd/root.go
index 6f5e190..878641b 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -2,8 +2,6 @@ package cmd
import (
"fmt"
- "github.com/wagoodman/dive/filetree"
- "github.com/wagoodman/dive/utils"
"io/ioutil"
"os"
@@ -12,6 +10,8 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
+ "github.com/wagoodman/dive/filetree"
+ "github.com/wagoodman/dive/utils"
)
var cfgFile string
@@ -122,12 +122,15 @@ func initConfig() {
// initLogging sets up the logging object with a formatter and location
func initLogging() {
+ var logFileObj *os.File
+ var err error
- if viper.GetBool("log.enabled") == false {
+ if viper.GetBool("log.enabled") {
+ logFileObj, err = os.OpenFile(viper.GetString("log.path"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
+ } else {
log.SetOutput(ioutil.Discard)
}
- logFileObj, err := os.OpenFile(viper.GetString("log.path"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
@@ -140,13 +143,8 @@ func initLogging() {
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
- log.SetLevel(level)
-
- if err != nil {
- fmt.Fprintln(os.Stderr, err)
- } else {
- log.SetOutput(logFileObj)
- }
+ log.SetLevel(level)
+ log.SetOutput(logFileObj)
log.Debug("Starting Dive...")
}