summaryrefslogtreecommitdiffstats
path: root/hugolib/site.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-11-01 22:27:42 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-11-03 12:06:23 +0100
commit4b7d3e57a40214a1269eda59731aa22a8f4463dd (patch)
tree0b258d8dc0c022081a03deac706a84c9dd4e90db /hugolib/site.go
parent4f3c0959635776278f5cc6ab7e5e262fdd3e1219 (diff)
Make WARN the new default log log level
This commit also pulls down the log level for a set of WARN statements to INFO. There should be no ERRORs or WARNINGs in a regular Hugo build. That is the story about the Boy Who Cried Wolf. Since the WARN log is now more visible, this commit also improves on some of them, most notable the "layout not found", which now would look something like this: ```bash WARN 2018/11/02 09:02:18 Found no layout for "home", language "en", output format "CSS": create a template below /layouts with one of these filenames: index.en.css.css, home.en.css.css, list.en.css.css, index.css.css, home.css.css, list.css.css, index.en.css, home.en.css, list.en.css, index.css, home.css, list.css, _default/index.en.css.css, _default/home.en.css.css, _default/list.en.css.css, _default/index.css.css, _default/home.css.css, _default/list.css.css, _default/index.en.css, _default/home.en.css, _default/list.en.css, _default/index.css, _default/home.css, _default/list.css ``` Fixes #5203
Diffstat (limited to 'hugolib/site.go')
-rw-r--r--hugolib/site.go35
1 files changed, 30 insertions, 5 deletions
diff --git a/hugolib/site.go b/hugolib/site.go
index e58dd39b2..761d4a6bd 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -956,7 +956,7 @@ func (s *Site) handleDataFile(r source.ReadableFile) error {
higherPrecedentMap := higherPrecedentData.(map[string]interface{})
for key, value := range data.(map[string]interface{}) {
if _, exists := higherPrecedentMap[key]; exists {
- s.Log.WARN.Printf("Data for key '%s' in path '%s' is overridden higher precedence data already in the data tree", key, r.Path())
+ s.Log.WARN.Printf("Data for key '%s' in path '%s' is overridden by higher precedence data already in the data tree", key, r.Path())
} else {
higherPrecedentMap[key] = value
}
@@ -1759,24 +1759,49 @@ func (s *Site) renderAndWritePage(statCounter *uint64, name string, targetPath s
return s.publisher.Publish(pd)
}
+var infoOnMissingLayout = map[string]bool{
+ // The 404 layout is very much optional in Hugo, but we do look for it.
+ "404": true,
+}
+
func (s *Site) renderForLayouts(name string, d interface{}, w io.Writer, layouts ...string) (err error) {
var templ tpl.Template
templ = s.findFirstTemplate(layouts...)
if templ == nil {
- s.Log.WARN.Printf("[%s] Unable to locate layout for %q: %s\n", s.Language.Lang, name, layouts)
+ log := s.Log.WARN
+ if infoOnMissingLayout[name] {
+ log = s.Log.INFO
+ }
+
+ if p, ok := d.(*PageOutput); ok {
+ log.Printf("Found no layout for %q, language %q, output format %q: create a template below /layouts with one of these filenames: %s\n", name, s.Language.Lang, p.outputFormat.Name, layoutsLogFormat(layouts))
+ } else {
+ log.Printf("Found no layout for %q, language %q: create a template below /layouts with one of these filenames: %s\n", name, s.Language.Lang, layoutsLogFormat(layouts))
+ }
return nil
}
if err = templ.Execute(w, d); err != nil {
- if p, ok := d.(*PageOutput); ok {
- return p.errorf(err, "render of %q failed", name)
- }
return _errors.Wrapf(err, "render of %q failed", name)
}
return
}
+func layoutsLogFormat(layouts []string) string {
+ var filtered []string
+ for _, l := range layouts {
+ // This is a technical prefix of no interest to the user.
+ lt := strings.TrimPrefix(l, "_text/")
+ // We have this in the lookup path for historical reasons.
+ lt = strings.TrimPrefix(lt, "page/")
+ filtered = append(filtered, lt)
+ }
+
+ filtered = helpers.UniqueStrings(filtered)
+ return strings.Join(filtered, ", ")
+}
+
func (s *Site) findFirstTemplate(layouts ...string) tpl.Template {
for _, layout := range layouts {
if templ, found := s.Tmpl.Lookup(layout); found {