commands: Cache logFile in createLogger
authorbogem <albertnigma@gmail.com>
Mon, 20 Feb 2017 08:53:11 +0000 (13:53 +0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 21 Feb 2017 14:08:45 +0000 (15:08 +0100)
commands/hugo.go

index cfadd226243facb2de89b6e08ccb628a4d40ed6e..65a3a955690bc3fcaeacc626161af2bcee9ab788 100644 (file)
@@ -398,22 +398,21 @@ func InitializeConfig(subCmdVs ...*cobra.Command) (*deps.DepsCfg, error) {
 func createLogger(cfg config.Provider) (*jww.Notepad, error) {
        var (
                logHandle       = ioutil.Discard
+               logThreshold    = jww.LevelWarn
+               logFile         = cfg.GetString("logFile")
                outHandle       = os.Stdout
                stdoutThreshold = jww.LevelError
-               logThreshold    = jww.LevelWarn
        )
 
-       if verboseLog || logging || (cfg.GetString("logFile") != "") {
-
+       if verboseLog || logging || (logFile != "") {
                var err error
-               if cfg.GetString("logFile") != "" {
-                       path := cfg.GetString("logFile")
-                       logHandle, err = os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
+               if logFile != "" {
+                       logHandle, err = os.OpenFile(logFile, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
                        if err != nil {
-                               return nil, newSystemError("Failed to open log file:", path, err)
+                               return nil, newSystemError("Failed to open log file:", logFile, err)
                        }
                } else {
-                       logHandle, err = ioutil.TempFile(os.TempDir(), "hugo")
+                       logHandle, err = ioutil.TempFile("", "hugo")
                        if err != nil {
                                return nil, newSystemError(err)
                        }