shithub: hugo

Download patch

ref: 7934db91694128f2b036e0b98a076fc679bf8d67
parent: 9e52477d94f56364fbdfa1a70692429eb05d7242
author: bogem <[email protected]>
date: Mon Feb 20 08:53:11 EST 2017

commands: Cache logFile in createLogger

--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -398,22 +398,21 @@
 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)
 			}