ref: 41857d036d5c02b4204e455111b98bf8e8caa402
parent: 75d855c086e68a3847ad5cb843073939df3b0d83
author: Bjørn Erik Pedersen <[email protected]>
date: Tue Feb 21 04:41:56 EST 2017
utils: Use local logger
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -366,7 +366,7 @@
cacheDir = cacheDir + helpers.FilePathSeparator
}
isDir, err := helpers.DirExists(cacheDir, cfg.Fs.Source)
- utils.CheckErr(err)
+ utils.CheckErr(cfg.Logger, err)
if !isDir {
mkdir(cacheDir)
}
@@ -481,7 +481,7 @@
v.OnConfigChange(func(e fsnotify.Event) {
c.Logger.FEEDBACK.Println("Config file changed:", e.Name)
// Force a full rebuild
- utils.CheckErr(c.recreateAndBuildSites(true))
+ utils.CheckErr(c.Logger, c.recreateAndBuildSites(true))
if !c.Cfg.GetBool("disableLiveReload") {
// Will block forever trying to write to a channel that nobody is reading if livereload isn't initialized
livereload.ForceRefresh()
@@ -504,7 +504,7 @@
if buildWatch {
c.Logger.FEEDBACK.Println("Watching for changes in", c.PathSpec().AbsPathify(c.Cfg.GetString("contentDir")))
c.Logger.FEEDBACK.Println("Press Ctrl+C to stop")
- utils.CheckErr(c.newWatcher(0))
+ utils.CheckErr(c.Logger, c.newWatcher(0))
}
return nil
@@ -841,7 +841,7 @@
c.Logger.FEEDBACK.Printf("Syncing all static files\n")
err := c.copyStatic()
if err != nil {
- utils.StopOnErr(err, fmt.Sprintf("Error copying static files to %s", publishDir))
+ utils.StopOnErr(c.Logger, err, fmt.Sprintf("Error copying static files to %s", publishDir))
}
} else {
staticSourceFs := c.getStaticSourceFs()
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -21,22 +21,22 @@
// CheckErr logs the messages given and then the error.
// TODO(bep) Remove this package.
-func CheckErr(err error, s ...string) {
+func CheckErr(logger *jww.Notepad, err error, s ...string) {
if err == nil {
return
}
if len(s) == 0 {
- jww.CRITICAL.Println(err)
+ logger.CRITICAL.Println(err)
return
}
for _, message := range s {
- jww.ERROR.Println(message)
+ logger.ERROR.Println(message)
}
- jww.ERROR.Println(err)
+ logger.ERROR.Println(err)
}
// StopOnErr exits on any error after logging it.
-func StopOnErr(err error, s ...string) {
+func StopOnErr(logger *jww.Notepad, err error, s ...string) {
if err == nil {
return
}
@@ -48,12 +48,12 @@
// Printing an empty string results in a error with
// no message, no bueno.
if newMessage != "" {
- jww.CRITICAL.Println(newMessage)
+ logger.CRITICAL.Println(newMessage)
}
}
for _, message := range s {
if message != "" {
- jww.CRITICAL.Println(message)
+ logger.CRITICAL.Println(message)
}
}
}