Suggestion to improve log file output of warnidf function to get cleaner logs

Hiho,

I am quite new to Hugo and struggled my way down with the template lookup rules… So I found warnidf and used it to output a warning if a block in baseof.html is not defined in the layout file. Helped me out a lot.

very cool that the warning can be suppressed :slight_smile:

Although it gives me the info I was looking for I suggest two changes to the output to make it more readable produce less noise.

<!DOCTYPE html>
<html lang="en">
   <head>
   </head>
   <body>
	  {{ block "missing" . }}
	  {{ warnidf "w-block-undefined" "undefined block for _defaults/baseof.html rendering page "}}
	  {{ end }}
      <main>{{ block "main" . }} {{ end }}</main>
   </body>
</html>

The output I get is:

hugo --cleanDestinationDir --gc --logLevel info
Start building sites …
hugo v0.123.6-92684f9a26838a46d1a81e3c250fef5207bcb735+extended windows/amd64 BuildDate=2024-02-28T18:29:40Z VendorInfo=gohugoio

INFO  static: removing all files from destination that don't exist in static dirs
INFO  static: syncing static files to \ duration 11.0497ms
INFO  build:  step process substep collect files 8 files_total 8 duration 511.1µs
INFO  build:  step process duration 511.1µs
INFO  build:  step assemble duration 0s
WARN  undefined block for _defaults/baseof.html rendering page
You can suppress this warning by adding the following to your site configuration:
ignoreLogs = ['w-block-undefined']
INFO  build:  step render substep pages site en outputFormat html duration 14.858ms

Wish

  • omit the You can suppresss this warning message
    • it’s clearly stated in the fmt.Warnidf docs
    • I would suppose users implementing that, know about
    • an advanced feature.
  • change the output to automatically include the id
    • so in normal use case this will be a one liner that can be easily grabbed when parsing the logs.
    • fits to the loggin style

So utilization of warnidf would be like that:

	  {{ warnidf "w-block-undefined" "for _defaults/baseof.html rendering page"}}
	  {{ warnidf "w-0001" "undefined block for _defaults/baseof.html rendering page"}}

with the following results (or similar)

INFO  build:  step process substep collect files 8 files_total 8 duration 0s
INFO  build:  step process duration 0s
INFO  build:  step assemble duration 0s
WARN  w-undefined-block for _defaults/baseof.html rendering page
WARN  w-0001 undefined block for _defaults/baseof.html rendering page XXX
or
WARN  [w-undefined-block] for _defaults/baseof.html rendering page
WARN  [w-0001] undefined block for _defaults/baseof.html rendering page XXX

p.s. ofc I would like to know which source file is currently rendered but that’s another story :wink:

I disagree. I remember when I started using Hugo, I kept getting errors (or warnings) about missing taxonomy. I appreciated the command line showing me how to suppress that warning/error without checking the docs or asking here.

Hi Arif,

I just tried to reproduce your comment and I did not get your mentioned suppress... text

  • there’s a one line warning about missing layout which imho is very good.
  • nothing about how to suppress it

I guess (without checking the source code) this is generated at a different level from hugo core, even before starting to process the page (in fact Hugo complains that it is missing)

> hugo --cleanDestinationDir --gc --logLevel debug
Start building sites …
hugo v0.123.6-92684f9a26838a46d1a81e3c250fef5207bcb735+extended windows/amd64 BuildDate=2024-02-28T18:29:40Z VendorInfo=gohugoio

INFO  static: removing all files from destination that don't exist in static dirs
INFO  static: syncing static files to \ duration 2.5461ms
INFO  build:  step process substep collect files 8 files_total 8 duration 513.5µs
INFO  build:  step process duration 1.0253ms
INFO  build:  step assemble duration 0s
WARN  found no layout file for "html" for kind "taxonomy": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.
INFO  build:  step render substep pages site en outputFormat html duration 8.6891ms
INFO  build:  step render pages 5 content 5 duration 9.2007ms
INFO  build:  step postProcess duration 0s
INFO  build:  duration 10.7458ms