utils: Use local logger
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 21 Feb 2017 08:41:56 +0000 (09:41 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 21 Feb 2017 08:41:56 +0000 (09:41 +0100)
commands/hugo.go
utils/utils.go

index 95e1c5864214b42e66659635b7285efd026225db..ad9aa316c80584e6ac0d38bdb43d01c17b1e69e5 100644 (file)
@@ -366,7 +366,7 @@ func InitializeConfig(subCmdVs ...*cobra.Command) (*deps.DepsCfg, error) {
                        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 @@ func (c *commandeer) watchConfig() {
        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 @@ func (c *commandeer) build(watches ...bool) error {
        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 @@ func (c *commandeer) newWatcher(port int) error {
                                                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()
index a3329c4a9fb34a3acbafea4bf1f92b20610f43c7..87357a26eacc36d97d0c74a730b933882e536fb6 100644 (file)
@@ -21,22 +21,22 @@ import (
 
 // 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 @@ func StopOnErr(err error, s ...string) {
                // 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)
                }
        }
 }