<p>The usual method for debugging a Craft site is to pull down a copy of the production database content, import it into your local development database and run a local copy of the site's code on your computer. You can run the site using Craft's <a href="https://getnitro.sh/" rel="nofollow noreferrer">Nitro</a> development environment, or use other local development environment frameworks like <a href="https://laravel.com/docs/8.x/valet" rel="nofollow noreferrer">Valet</a> or <a href="https://www.mamp.info/" rel="nofollow noreferrer">MAMP</a>.</p>
<p>Once you have this local development site running, you can make changes to the templates to help debug issues or view the properties of objects, just by modifying the Twig templates. The Twig <a href="https://twig.symfony.com/doc/2.x/functions/dump.html" rel="nofollow noreferrer">dump</a> function is useful for viewing the contents of an object to see which properties you have available:</p>
<pre><code>{% for tweet in craft.ssTwitterFeed.displayPost( '4' ) %}
    {{ dump(tweet) }}
{% endfor %}
</code></pre>
<p>If you're running the site with devMode enabled, the <a href="https://craftcms.com/docs/3.x/dev/tags.html#dd" rel="nofollow noreferrer">dd</a> tag (Dump-and-die) is also helpful. This will dump out the variable and nothing else, i.e. your page won't render but instead you will get a formatted dump of the variable you're inspecting:</p>
<pre><code>{% dd(craft.ssTwitterFeed.displayPost('4')) %}
</code></pre>

CC BY-SA 4.0
2021-03-12T12:42:19.880Z
Awesome info thank you for sharing your knowledge - Random question, but is it possible to enable DEV mode against a single page in craft? 

I have added a dev page to the website so I can manipulate the template free of effecting a customer facing page - but cannot seem to get Dump to work on said page so imagine that DEV mode needs to be enabled for this.
Wally
CC BY-SA 4.0
2021-03-12T13:01:23.597Z
Unfortunately no, `devMode` is a global config setting that applies to the whole environment.
Martin Spain
CC BY-SA 4.0
2021-03-12T17:31:39.183Z
You could enable ``devMode`` on individual pages with something like ``'devMode' => ($_SERVER['REQUEST_URI'] == '/whatever/page')``
RitterKnight
CC BY-SA 4.0
2021-03-13T18:30:04.367Z
Clever! Very neat solution.
Martin Spain
CC BY-SA 4.0
2021-03-12T12:28:12.620Z
2021-03-12T12:37:48.120Z
2021-03-12T12:37:48.120Z
Martin Spain
<p>So I'm used to JS where I can <code>console.log()</code> most errors to assess the best way to debug what's going on.</p>
<p>In Craft, as many of the sites I am working on are live and in production and I struggle (horribly) to find solutions to issues! Also because the site is live I cannot enable dev mode....</p>
<p>Is there a way to console log errors? (from looking at posts here I do not think there is, but I must ask directly).</p>
<p>If there is not, maybe someone could explain how they would handle this situation (Which I am currently in so this is not hypothetical).</p>
<p>I'm using SS twitter feed to populate a page with twitter tweets.</p>
<p>I would like to see what data is available to me, to use (or not use if some posts are different - and have to write conditions for).</p>
<p>In JS I would console log this i.e.</p>
<pre><code>var tweets = getTweetsFunction 
console.log(tweets)
</code></pre>
<p>this would display an array of objects and from there I could find out what fields are available.</p>
<p>But in Twig, posting</p>
<pre><code>{% for tweet in craft.ssTwitterFeed.displayPost( '4' ) %}
  {{tweet}}
{&amp; endfor &amp;}
</code></pre>
<p>just gives me the &quot;Server error&quot; message.</p>
<p>Side note here, I have enabled the craft dev tool bar</p>
<p><a href="https://i.sstatic.net/caF9p.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/caF9p.png" alt="enter image description here" /></a></p>
<p>And can see that it has a log section, can you log twig variables to this section to review them?</p>
<p>I understand that this might be a really basic question but it's driving me mad that every wrong turn ends in Server Error.</p>
<p>Thanks for any help,
W</p>
<hr />
<p>As of craft 3.2 dump and die is enabled even for sites that are running without dev mode - dump and die is the solution to this issue.</p>

<debugging>
Error handling in Craft
# Error handling in Craft

(Asked by: username_0 on 2021-03-12)

So I'm used to JS where I can console.log() most errors to assess the best way to debug what's going on.
In Craft, as many of the sites I am working on are live and in production and I struggle (horribly) to find solutions to issues! Also because the site is live I cannot enable dev mode....
Is there a way to console log errors? (from looking at posts here I do not think there is, but I must ask directly).
If there is not, maybe someone could explain how they would handle this situation (Which I am currently in so this is not hypothetical).
I'm using SS twitter feed to populate a page with twitter tweets.
I would like to see what data is available to me, to use (or not use if some posts are different - and have to write conditions for).
In JS I would console log this i.e.
var tweets = getTweetsFunction 
console.log(tweets)

this would display an array of objects and from there I could find out what fields are available.
But in Twig, posting
{% for tweet in craft.ssTwitterFeed.displayPost( '4' ) %}
  {{tweet}}
{& endfor &}

just gives me the "Server error" message.
Side note here, I have enabled the craft dev tool bar

And can see that it has a log section, can you log twig variables to this section to review them?
I understand that this might be a really basic question but it's driving me mad that every wrong turn ends in Server Error.
Thanks for any help,
W

As of craft 3.2 dump and die is enabled even for sites that are running without dev mode - dump and die is the solution to this issue.

**Tags:** debugging

---

## 1 answers

### Answer by username_1 on 2021-03-12. Score: 2

The usual method for debugging a Craft site is to pull down a copy of the production database content, import it into your local development database and run a local copy of the site's code on your computer. You can run the site using Craft's Nitro development environment, or use other local development environment frameworks like Valet or MAMP.
Once you have this local development site running, you can make changes to the templates to help debug issues or view the properties of objects, just by modifying the Twig templates. The Twig dump function is useful for viewing the contents of an object to see which properties you have available:
{% for tweet in craft.ssTwitterFeed.displayPost( '4' ) %}
    {{ dump(tweet) }}
{% endfor %}

If you're running the site with devMode enabled, the dd tag (Dump-and-die) is also helpful. This will dump out the variable and nothing else, i.e. your page won't render but instead you will get a formatted dump of the variable you're inspecting:
{% dd(craft.ssTwitterFeed.displayPost('4')) %}

> **Comments:**
> **username_0**: Awesome info thank you for sharing your knowledge - Random question, but is it possible to enable DEV mode against a single page in craft?   I have added a dev page to the website so I can manipulate the template free of effecting a customer facing page - but cannot seem to get Dump to work on said page so imagine that DEV mode needs to be enabled for this.  
> **username_1**: Unfortunately no, `devMode` is a global config setting that applies to the whole environment.  
> **username_2**: You could enable ``devMode`` on individual pages with something like ``'devMode' => ($_SERVER['REQUEST_URI'] == '/whatever/page')``  
> **username_1**: Clever! Very neat solution.  

---

