Permalink
Browse files

utils: Use local logger

  • Loading branch information...
bep committed Feb 21, 2017
1 parent 75d855c commit 41857d036d5c02b4204e455111b98bf8e8caa402
Showing with 11 additions and 11 deletions.
  1. +4 −4 commands/hugo.go
  2. +7 −7 utils/utils.go
View
@@ -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()
View
@@ -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)
}
}
}

0 comments on commit 41857d0

Please sign in to comment.