<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: John Meade</title>
    <description>The latest articles on DEV Community by John Meade (@johnmeadewebdev).</description>
    <link>https://dev.to/johnmeadewebdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F169018%2Fdf0ac08f-b322-47c3-a2c8-15608b37a474.jpeg</url>
      <title>DEV Community: John Meade</title>
      <link>https://dev.to/johnmeadewebdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johnmeadewebdev"/>
    <language>en</language>
    <item>
      <title>A Simple Approach To Using Console.log For Debugging</title>
      <dc:creator>John Meade</dc:creator>
      <pubDate>Tue, 12 Jan 2021 06:12:48 +0000</pubDate>
      <link>https://dev.to/johnmeadewebdev/a-simple-approach-to-using-console-log-for-debugging-48n</link>
      <guid>https://dev.to/johnmeadewebdev/a-simple-approach-to-using-console-log-for-debugging-48n</guid>
      <description>&lt;p&gt;&lt;em&gt;Some people scoff at the console.log, some people - present company included - cherish the simple method. Here's an easy way to use it to your advantage on your front-end&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A Global Constant
&lt;/h2&gt;

&lt;p&gt;Key to this working well is to place a constant in the global namespace. You can pick where you want it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.debugCLs = true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now as you go about in your code you can make a decision on if there are sections where you want specific and quick console logs available to you. You may have some troublesome blocks that you just want to switch on and off as you debug, or any number of other scenarios.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
    ...to do this thing
} catch(e) {
    window.debugCLs &amp;amp;&amp;amp; console.log(e);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to run a file with these logs activated, simply switch your constant to the value of &lt;code&gt;true&lt;/code&gt;, save, and run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Organizing Your Logs
&lt;/h2&gt;

&lt;p&gt;You can organize your logs by color (or other styles) to help you quickly sort through things in the console, or to make sure your eye immediately is drawn to specific priority logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const modelObj = {
    value: 10,
}

try {
    const notAConst = (modelObj.value.props[0]);
} catch(e) {
    window.debugCLs &amp;amp;&amp;amp; console.log('%c PRIORITY ','color:white;background-color:#044c94', e);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TWVQY5Qm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t11kprcygayoemdhg1uv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TWVQY5Qm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t11kprcygayoemdhg1uv.png" alt="Color-coded label for a debugging console.log"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Less Is More
&lt;/h2&gt;

&lt;p&gt;Obviously there is always too much of a good thing. You don't want to be sorting through a console with 500 lines of logging that are color-coded with 255 colors. That being said, four to five different categories could just help you out a bit.&lt;/p&gt;

&lt;p&gt;And if you want to make it even more slick to handle, make your global variable an object that allows you to turn large categories on and off:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.debugCLs = {
    apiCalls = true;
    socketNegotiations = false;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Happy Coding
&lt;/h2&gt;

&lt;p&gt;...and remember to always code for good :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
