Verbose Logging: Your Magnifying Glass for Bad Application Behavior
Tags: logging, programming, devops
Published: 2019-07-22 20:53:14

<!-- wp:paragraph -->
<p>You probably don't think of verbose logging as the stuff that hackathons and startups are made of.&nbsp; Nor would most programmers consider it an especially advanced technique.&nbsp; But it <em>is</em> important, and enough people ask about it that it's worth covering.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this post, we'll take a look at:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>What verbose logging is</li><li>Why people use it</li><li>And how to both consume it and produce it from your applications</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>By the time you're done, you'll have a firm grasp of the technique.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Part of the reason that so many people inquire about the subject of verbose logging is that it's kind of general in the same way that searching for "logging" is general.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So let's start by at least getting more specific with a definition.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":814,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://library.scalyr.com/2018/07/19175427/Chat-bubbles-with-Scalyr-colors.png" alt="" class="wp-image-814"/></figure></div>
<!-- /wp:image -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:heading {"level":3} -->
<h3>What Is Verbose Logging?</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The definition of verbose logging piggybacks heavily on the idea of logging in general from your software.&nbsp; So let's define logging:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p>In software, logging is the practice of recording to a persistent medium events that occur while the software runs.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>This can cover a lot of ground, from the recording of critical errors to logging normal purchase transactions for an e-commerce app to documenting every method that the software executes.&nbsp; The particulars will vary widely by the nature of the software, the preferences of the team, and the context in which the software runs.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>One of the most common ways to reason about a logging approach is through the use of <a href="https://www.scalyr.com/blog/logging-levels/">so-called logging levels</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>These allow you to control how "chatty" your logs are, ranging from "log only critical errors" to "log everything and the kitchen sink."&nbsp; And verbose logging falls at the&nbsp;<em>extreme&nbsp;</em>kitchen-sink end.&nbsp; It's a shorthand way to express the idea that you're knowingly recording events with <a href="https://en.wikipedia.org/wiki/Signal-to-noise_ratio">an extremely high rate of noise</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So "verbose logging" becomes a common shorthand and has this definition:</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p>In software, <strong>verbose logging</strong> is the practice of recording to a persistent medium <strong>as much information as you possibly can</strong> about events that occur while the software runs.</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>It's also worth mentioning that verbose logging is generally a mode that you can toggle on and off.&nbsp; In other words, via logging levels or a simple flag, software developers give you the ability to temporarily "go verbose" rather than adopting verbose logging as the default or only state of the software.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Why Do People Use This Technique?</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now that we've established what this is, the next question is "Why would they do it?"</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can probably infer the reasoning, to an extent.&nbsp; When would people, in general, want to err on the side of furnishing too much information?</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You do this when you're facing an intractable problem and are thinking that any clue might help.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So it goes with verbose logging.&nbsp; You generally adopt this logging mode when you're debugging or trying to hunt down some production support issue.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If the solution isn't immediately obvious, you flip the toggle for verbose mode and hope that the upcoming flood of information proves helpful somehow.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This generally isn't the highest leverage technique.&nbsp; In other words, when you enter verbose mode, grab yourself a cup of coffee and prepare to spend a while sifting through a lot of output looking for anything that seems helpful.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Consuming Verbose Logging: Some Examples</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>When it comes to logging, there are two main parties to the activity: the producers and the consumers.&nbsp; Let's take a look at the consumption side of logging in verbose mode first, with some examples.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Operating System Logs</h4>
<!-- /wp:heading -->

<!-- wp:image {"id":815,"align":"right"} -->
<div class="wp-block-image"><figure class="alignright"><img src="https://library.scalyr.com/2018/07/19175428/Pull-quote-If-the-solution-isnt-immediately-obvious-you-flip-the-toggle-for-verbose-mode.png" alt="" class="wp-image-815"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Your operating system produces a pretty impressive cache of logs, if you're inclined <a href="https://technet.microsoft.com/en-us/library/aa996634(v=exchg.65).aspx">to look at them</a>.&nbsp; As a consumer, you'll rarely want to do this, except when the computer acts up.&nbsp; In googling the specifics of a problem you have or asking for help in a forum, you might encounter advice to <a href="https://technet.microsoft.com/en-us/library/aa996634(v=exchg.65).aspx">enable verbose logging for some facet of the OS</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Installers</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Imagine that you're trying to install some piece of software and you get a cryptic error like, "Not Allowed, Install Aborted."</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Sadly, this kind of thing happens a lot.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Software installations tend to produce logs, but those might not be enough.&nbsp; And so you would reasonably turn to running the installation in verbose mode, which <a href="https://support.microsoft.com/en-us/help/2545723/how-to-enable-microsoft-installer-logging-and-verbose-logging-to-gathe">many installers offer</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Command Line</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Perhaps the simplest, quickest example of finding verbose information happens when you go to the command line.&nbsp; For instance, take <a href="https://www.techonthenet.com/linux/commands/gzip.php">the gzip command</a> in a Linux environment.&nbsp; This is one of the simplest commands imaginable--give gzip a file and it compresses or decompresses it.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But if you add the "-v" flag to it, you tell it to run in verbose mode.&nbsp; It then obliges by showing you additional information that includes the compression/decompression percentage.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":4} -->
<h4>Troubleshooting Your Own Software</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The last quick consumption example that I'll mention is one where you're responsible for the software in question.&nbsp; You might be anywhere on <a href="https://scalyr.com/blog/devops-past-present-and-future/">the DevOps spectrum</a>&nbsp;and in need of information for troubleshooting.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this case, you'll typically change a configuration setting in a config file or in a database that your code uses.&nbsp; "Flip to mode," you'll tell it, and then you'll start your search for the problem.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Producing Verbose Logging in Your Own Application</h3>
<!-- /wp:heading -->

<!-- wp:image {"id":816,"align":"left"} -->
<div class="wp-block-image"><figure class="alignleft"><img src="https://library.scalyr.com/2018/07/19175428/Pull-quote-Doing-this-requiresa-relatively-sophisticated-approach-to-application-logging.png" alt="" class="wp-image-816"/></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>That provides a nice segue into the other side of things: producing verbose logging from your application.&nbsp; Doing this requires, first and foremost, a <a href="https://www.scalyr.com/blog/application-logging-practices-adopt/">relatively sophisticated approach to application logging</a>.&nbsp; You need to be doing it, of course, but you also need the aforementioned configurable log levels and a way to toggle among them.&nbsp; And you should also be <a href="https://www.scalyr.com/blog/be-kind-to-your-log-file-and-those-reading-it/">producing well-formatted log files</a>, lest you bury consumers in a tidal wave of useless information.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>With all of this in place, give some thought to your most verbose level of logging.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>What would help with troubleshooting?&nbsp; Tons and tons of context around each message?&nbsp; A note about where in the code you're logging from?&nbsp; An exhaustive dump of inputs to and outputs from your software?&nbsp; You'll have to decide based on context.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>And perhaps the most important consideration for offering a verbose mode is making the toggling easy and foolproof for anyone using it.&nbsp; If you default to verbose mode or forget to turn it off, you'll quickly <a href="https://www.scalyr.com/blog/log-file-too-big/">create unmanageable log files</a>&nbsp;while making life really hard on anyone looking for basic information rather than needles in haystacks.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3>Looking Forward: Verbose As the New Normal</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In closing, it's worth mentioning that the old pitfalls of verbose logging may be falling away with advances in technique and technology.&nbsp; Verbose mode has, historically, favored the tradeoff of tons of information for difficulty finding and using the information you actually need.&nbsp; But <a href="https://www.scalyr.com/blog/log-management-need/">modern log management solutions</a> are changing the game in that regard, by offering the following:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Taking care of log aggregation and storage for you.</li><li>Parsing the log messages and turning them into data.</li><li>Offering intelligent indexing and search.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>So you should understand verbose mode for what it has historically been: a way to bury yourself in information with the hope that some of it will help.&nbsp; But you should also understand it for what it's becoming: a way to have your cake and to eat it too.</p>
<!-- /wp:paragraph -->