-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add debugf function #11739
Comments
What is the motivation behind this? To clarify:
Related: #10725 |
Actually the motivation would be better debugging infrastructure for Hugo themes. While it is true that it's possible to get rid of the "anti log flooding behaviour", there are certain situations where it is just counter intuitive and thus annoying. Anyways, as you've mentioned the logLevels: There is currently no way to set a level with This short table illustrates the idea further:
Notes
And by the way: Having a |
I am in favor of doing this; need bep's approval before proceeding. Over the past week I've added |
So, I kind of want this myself (I'm using
Also, having a console based debug tool that has no easy connection to where it gets logged (which template for which page`?) is not very useful. I suspect what we're looking for is is something else, but I'm not totally sure what. |
Would adding a
|
@bep:
And don't underestimate (feature) greedy developers, I won't mind:
|
In my head there are 2 distinctive kinds of debug problems:
Having the number 2s left after you've solved a particular problem is, in my head, never a great idea. It will make future troubleshooting accumulatively harder to do over time, and this gets especially annoying when you inherit debug statements from other developer (e.g. theme/modules). |
I totally agree with that distinction but don't see a pragmatic solution: Logging frameworks usually solve this by adding just another level like Just for completeness to other readers: The used logging framework has Another approach would be be able to pass a |
Going back to the beginning, it seems like the primary gripe with using
...but I guess others do. Maybe we could not mute duplicate warnings with |
I'll try another approach in justifying the desire to have this. I'm aware that this isn't a strong argument: From the discussion so far it is my understanding that we are at the crossroads of two paths:
Since i'm the original reporter I'm certainly in favor of the first, but can definitely live with the second as well. And while I'm at it, I would like to use the opportunity to stress the importance of good error messages. By "good" I mean that a error message should always state exactly what went wrong where (at least which template is "throwing", for which content file would be nice, as well as giving a hint how to fix things). Bad error messages in this sense are all that wouldn't give away any context at all.
I'm not sure how much of these "bad" messages still exist in 0.123.0. |
We don't. If I remember correctly, we only de-duplicate from >= warning. |
I tested again with v0.123.0-DEV. Duplicate warning messages are muted regardless of logLevel. I added this to the docs a while back: |
I'm not sure I follow. Warning is a log level. We filter out duplicate log items of log level >= Warning. This has nothing to do with the As to this issue: I still think that a What I think we need to improve on is:
Or something like that. |
I guess I was confused by this conversation:
I'm fine with adding a counter, as shown above, to make warning messages unique. |
Just to clear things up, my understanding of @jmooring 's proposal was, that there could be a logic witch would disable deduplication of a massage (of any level - the only viable candidate being While I agree with @bep 's assesment about needed infrastructure, i tend to disagree on the partly patronizing point, which would be arguing with the multi treaded nature of the build process.
Because it's unexpected. There still is some interest in having this function, by I guess it's there since people are extrapolating from the name of Another (quite weak) idea regarding this proposal would be to integrate Back to the first comments: I get it, it's certainly not only about adding a function and I'm also guilty of broadening the scope: Since we certainly agree that the is much to be desired regarding debugging, I would open new ones, tightening the scope for each:
What do you think? |
I really, really appreciate your considerations and the time you put into improving the debugging experience of Hugo for developers. Maybe I can provide a real-world example of the contortions I am using in my templates to keep up your motivation to improve the debugging infrastructure of Hugo 😃 At the top of every template, I define the following preamble:
{{- $template := "claris/_functions/resources/images/render-images" }}
{{- $dbg := printf "%s[%s]" (replaceRE `.*?((?:[^/]+/){,2})$` `$1` page.RelPermalink) (replaceRE `.*?([^/]+)$` `$1` $template) }} To determine, which templates output debug messages, I use a number of approaches:
{{- $debug := and true (or .Debug (page.Param "clarisdebug") ) }} Note that restricting the output to a single page helps keeping the output tractable in a multi-threaded application like Hugo. For every single debug output, I need three lines: {{- if $debug }}
{{- warnf "%s Processing variant=%v with .version:\n%v" $dbg $variantName (jsonify (dict "indent" " ") $variantMeta.version) }}
{{- end }} When the output gets too verbose, I disable some of those temporarily: {{- if and false $debug }}
{{- warnf "%s Processing imageMeta:\n%v" $dbg (jsonify (dict "indent" " ") $imageMeta) }}
{{- end }} I think there are a great number of ways Hugo could contribute to simplify the life of template developers such as myself. A good start from my humble perspective would be the following:
This would turn the above code into just a {{- debugf "Processing variant=%v with .version:\n%v" $variantName (jsonify (dict "indent" " ") $variantMeta.version) }} To temporarily disable a {{- /* {{- debugf "%s Processing imageMeta:\n%v" $dbg (jsonify (dict "indent" " ") $imageMeta) }} */ -}} |
@simonheimlicher Thanks for those suggestions, in my "kitchen sink"-theme I already do that partly (currently missing the I'm well aware that there are ways to reach the proposed goal, but they aren't a integral part of the core infrastructure. But providing your examples definitely helps in demonstrating that there is clear demand for improving the "tooling" of theme development. |
See https://discourse.gohugo.io/t/add-debugf-function/45625
The text was updated successfully, but these errors were encountered: