Skip to main content
GOHUGO

Debug

Debug everything in Hugo! This module for GoHugo adds debugging partials for everything you need to debug.

Notes

  • This is a GoHugo module to use while you are developing your theme or website. It slows down the build process. Knowledge about variables in our template and NOT speed is our main priority. It is advised to add the module only the development configuration or check if the layout is processed by the development server to minimise its impact.
  • This module is based on the work in kaushalmodi/hugo-debugprint.

Usage

Either add disabled = true to your live server configuration or check, if you are on a development server by using {{- if site.IsServer -}} around your calls to the partials.

A quick sample for its usage is the following debugging of a pages data:

 1{{- if site.IsServer -}}
 2  <footer id="debugging">
 3    <div class="container">
 4      <div class="row">
 5        <div class="col-12">
 6          {{- partial "debugprint.html" . -}}
 7        </div>
 8      </div>
 9    </div>
10  </footer>
11{{- end -}}

Debug from within layouts

To print a variable in one of your layouts:

 1{{ partial "debugprint" . }}
 2{{ partial "debugprint" .Params }}
 3{{ partial "debugprint" site }}
 4{{ partial "debugprint" site.Menus }}
 5{{ partial "debugprint" .GitInfo }}
 6{{ partial "debugprint" .Resources }}
 7{{ partial "debugprint" .File }}
 8
 9{{/* in shortcodes */}}
10{{ partial "debugprint" . }} <!-- this will debug the internals of the shortcode -->
11{{ partial "debugprint" .Position }} <!-- this will show where the shortcode was called -->

Exchange the context . with whatever variable you want to debug. Sub-collections or sub-slices might require extra setup to be debugged, depending on the structure and the type of the values.

Debug from within markdown (content) files

To debug page data from within a Markdown file:

1{{< debugprint >}} <!-- the same as -->
2{{< debugprint "page" >}} <!-- debugs page variable -->
3{{< debugprint "params" >}} <!-- debugs page params -->
4{{< debugprint "site" >}} <!-- debug sites params -->
5{{< debugprint param="bla" >}} <!-- debugs .Params.bla -->

Debugging from within Markdown requires explicit configuration in the shortcode template. Open a new issue if you require a specific debugging subject.

Debug from your layout file into the CLI/server log

Some times we developers want to inform and warn our users, or even throw an error. The debug partial is your connection to the CLI with some more options than GoHugo’s internal error functionality.

Read On

Debug pages in a comprehensive format

While all other debugging options above are flexible options to debug any value, the debugpage partial opts to show a bunch of interesting information about the page object it is called on. It’s quite specific and tries to cut out the noise.

You can add the following call to any layout file:

1{{ partialCached "debugpage.html" . . }}

or by using the following shortcode in your Markdown:

1{{< debugpage >}}

The Markdown shortcode will take the context of the currently parsed page while the template call will take what you hand over.

Configuration

The debug component is configurable via the params section in your configuration. The following samples will assume your configuration lives in config/_default/params.toml. If you are using a root level configuration don’t forget to add params. in front of each section and put it at the right place.

1[dnb]
2  [dnb.debug]
3    debuglevel = 8
4    disablenote = false
5    namespace = 'dnb'
1dnb:
2  debug:
3    debuglevel: 8
4    disablenote: false
5    namespace: dnb
1{
2   "dnb": {
3      "debug": {
4         "debuglevel": 8,
5         "disablenote": false,
6         "namespace": "dnb"
7      }
8   }
9}
  • namespace: (string) namespace slug for your plugin/theme. keep it short. three characters are enough. There is no restriction on this, but think about the look of the loglines with longer namespaces.
  • debuglevel: (number, 0 to 10) set the severity level that should maximally be shown. The higher the more info/debug on your CLI. 10 is maximum and can be helpful to debug issues.
  • disablenote: (bool) disables the note at the beginning that the debug module is used.
Back to top
Back Forward