Repository: gohugoio/hugo (language: go)

Issue:
The "Web Server is available at ..." on rebuilds needs to come after any log statements (before Total ...)
Also 

* make sure it's not printed on `hugo -w`.
* print it for all rebuilds, including config changes


Discussion / hints:
Yeah, I saw this when testing https://github.com/gohugoio/hugo/pull/12367 but didn't worry about it since log statements continue after the "Total" display anyway. I briefly looked at this yesterday, and couldn't figure out an expedient way  to handle it.
>log statements continue after the "Total" display

I'm pretty sure "Total in ..." is the last entry for a given build. In normal scenarios it is the last entry. I understand that our writing to stdout isn't synchronised or anything, but as it is now, it looks ... messy when running with `--logLevel info`.
With multilingual sites I see:

```text
INFO  build:  step render substep pages site en outputFormat html duration 3.509292ms
INFO  build:  step render substep pages site en outputFormat rss duration 1.989274ms
INFO  build:  step render substep pages site de outputFormat html duration 510.836µs
INFO  build:  step render substep pages site de outputFormat rss duration 554.714µs
INFO  build:  step render pages 5 content 2 duration 9.811543ms
INFO  build:  step postProcess duration 65.566µs
INFO  build:  duration 28.630744ms
Total in 29 ms
INFO  build:  step render substep pages site en outputFormat html duration 563.61µs
INFO  build:  step render substep pages site en outputFormat rss duration 466.159µs
INFO  build:  step render substep pages site de outputFormat html duration 552.515µs
INFO  build:  step render substep pages site de outputFormat rss duration 337.426µs
INFO  build:  step render pages 0 content 0 duration 3.2983ms
INFO  build:  step postProcess duration 52.173µs
INFO  build:  duration 3.936471ms
```

Fix patch:
diff --git a/commands/commandeer.go b/commands/commandeer.go
index 616a3c867f4..5d4f02a4de6 100644
--- a/commands/commandeer.go
+++ b/commands/commandeer.go
@@ -327,12 +327,12 @@ func (r *rootCommand) Name() string {
 }
 
 func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args []string) error {
+	b := newHugoBuilder(r, nil)
+
 	if !r.buildWatch {
-		defer r.timeTrack(time.Now(), "Total")
+		defer b.postBuild("Total", time.Now())
 	}
 
-	b := newHugoBuilder(r, nil)
-
 	if err := b.loadConfig(cd, false); err != nil {
 		return err
 	}
diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go
index f5bc730873a..657048d481a 100644
--- a/commands/hugobuilder.go
+++ b/commands/hugobuilder.go
@@ -75,9 +75,14 @@ type hugoBuilder struct {
 	errState hugoBuilderErrState
 }
 
+var errConfigNotSet = errors.New("config not set")
+
 func (c *hugoBuilder) withConfE(fn func(conf *commonConfig) error) error {
 	c.confmu.Lock()
 	defer c.confmu.Unlock()
+	if c.conf == nil {
+		return errConfigNotSet
+	}
 	return fn(c.conf)
 }
 
@@ -585,7 +590,7 @@ func (c *hugoBuilder) fullRebuild(changeType string) {
 			time.Sleep(2 * time.Second)
 		}()
 
-		defer c.r.timeTrack(time.Now(), "Rebuilt")
+		defer c.postBuild("Rebuilt", time.Now())
 
 		err := c.reloadConfig()
 		if err != nil {
@@ -855,7 +860,7 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
 		c.changeDetector.PrepareNew()
 
 		func() {
-			defer c.r.timeTrack(time.Now(), "Total")
+			defer c.postBuild("Total", time.Now())
 			if err := c.rebuildSites(dynamicEvents); err != nil {
 				c.handleBuildErr(err, "Rebuild failed")
 			}
@@ -901,6 +906,13 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
 	}
 }
 
+func (c *hugoBuilder) postBuild(what string, start time.Time) {
+	if h, err := c.hugo(); err == nil && h.Conf.Running() {
+		h.LogServerAddresses()
+	}
+	c.r.timeTrack(start, what)
+}
+
 func (c *hugoBuilder) hugo() (*hugolib.HugoSites, error) {
 	var h *hugolib.HugoSites
 	if err := c.withConfE(func(conf *commonConfig) error {
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index 3beb072e3c7..a4546ff4492 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -951,12 +951,10 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
 		}
 	}
 
-	h.logServerAddresses()
-
 	return nil
 }
 
-func (h *HugoSites) logServerAddresses() {
+func (h *HugoSites) LogServerAddresses() {
 	if h.hugoInfo.IsMultihost() {
 		for _, s := range h.Sites {
 			h.Log.Printf("Web Server is available at %s (bind address %s) %s\n", s.conf.C.BaseURL, s.conf.C.ServerInterface, s.Language().Lang)


Test patch: