<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Moreau on Medium]]></title>
        <description><![CDATA[Stories by David Moreau on Medium]]></description>
        <link>https://medium.com/@dav.m85?source=rss-c95657039a37------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-aWgxbay9U1vNc1RVb-AYA.jpeg</url>
            <title>Stories by David Moreau on Medium</title>
            <link>https://medium.com/@dav.m85?source=rss-c95657039a37------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 05:27:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dav.m85/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Logging aboard the Millenium Falcon]]></title>
            <link>https://medium.com/@dav.m85/logging-aboard-the-millenium-falcon-4d5097a547d6?source=rss-c95657039a37------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d5097a547d6</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[monolog]]></category>
            <category><![CDATA[star-wars]]></category>
            <category><![CDATA[kibana]]></category>
            <category><![CDATA[logging]]></category>
            <dc:creator><![CDATA[David Moreau]]></dc:creator>
            <pubDate>Tue, 20 Sep 2016 19:20:15 GMT</pubDate>
            <atom:updated>2016-09-21T15:21:46.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggqV-8N2HsBZixpcUHR0sA.jpeg" /></figure><p><a href="http://starwars.wikia.com/wiki/Millennium_Falcon">Millenium Falcon</a> never wants to jump hyperspace, unless R2-D2 fixes it for you. How happens that even infamous Han Solo struggles to understand his spaceship? Is it because the Corellians have a very peculiar sense of logging humor? Let’s find out!</p><p>People are sometimes reading the logs. They should be taken care of (logs, not people) like any other piece of code, with readability in mind. If MF log system was following these 7 rules, maybe Star Wars wouldn’t have been the same.</p><p>Let’s assume MF’s onboard computer is in <strong>php</strong>, even if we are all convinced <a href="https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/">that it is a terrible language</a>. <strong>$logger</strong> will be a correctly configured <a href="https://github.com/Seldaek/monolog"><strong>Monolog\Logger</strong> instance</a>.</p><h4>What are you talking about?</h4><p>Try to explain what happens, making sentences and giving context. <a href="http://www.pleated-jeans.com/2012/08/16/20-images-that-prove-grammar-and-punctuation-are-important">Yeah this is important</a>. Not everyone understands what an integer means, that’s why rfc2616 HTTP status codes has a string explanation sent in the headers too.</p><pre>$shieldLevel = 20;<br><strong>// …should be 100 when encountering an Imperial Destroyer, right ?</strong></pre><pre><strong>// Bad</strong><br>$logger-&gt;info($shieldLevel); <br><strong>// MF - 20</strong></pre><pre><strong>// Good</strong><br>$logger-&gt;info(“Shieldlevel: $shieldLevel%”);<br><strong>// MF - Shieldlevel: 20%</strong></pre><pre><strong>// Even better, embedding metadata</strong><br>$logger-&gt;info(“Shieldlevel: $shieldLevel%”, [‘shieldLevel’ =&gt; $shieldLevel]); </pre><p>Another example if you weren’t convinced:</p><pre><strong>// Bad</strong><br>$logger-&gt;info(“no hd”);<br><strong>// Chewie - Brwarrga hahagh (TN, &quot;hard drive or hyper drive?&quot;)</strong></pre><pre><strong>// Good, Subject-Verb-Complement, punctuation, thank you school!</strong><br>$logger-&gt;info(“Hyperdrive reports failure, Bezel condensator is discharged”);</pre><h4>Do not remove information</h4><p>Some habits can lead to information being truncated from the log messages.</p><pre>try {<br>    throw new \Exception(“oops”);<br>} catch(\Exception $e) {<br>    <strong>// Bad</strong><br>    $logger-&gt;error($e-&gt;getMessage()); <br>    <strong>// MF - oops</strong></pre><pre>    <strong>// Good</strong><br>    $logger-&gt;error((string) $e);<br>    <strong>// MF - oops in Example at line:...<br></strong>}</pre><h4>Causality principle</h4><p>We dwell in many threads running systems, and two nearby log entries can be separated by a lot of noise</p><pre><strong>// Bad</strong><br>$logger-&gt;info(“The hyperdrive just failed”);<br>$logger-&gt;info(“It could be related to the Bezel condensator”);<br><br><strong>// MF - The hyperdrive just failed (thread 1)<br>// MF - Cargo door is open (thread 2)<br>// MF - Picking up weird proximity signals (thread 3)<br>// MF - It could be related to the Bezel condensator (thread 1)<br>// Han — Proximity probes are complaining about Bezel, disable it!</strong><br> <br><strong>// Good</strong><br>$logger-&gt;info(“The hyperdrive just failed, probably because of the Bezel condensator”);</pre><h4>Horribly wrong level</h4><p>Logging levels are your very own noise/signal ratio protection. So design logs at the righteous level. Luckily, each <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md">harness has its definition</a>, stick to it.</p><pre><strong>// Bad</strong><br>$logger-&gt;debug(“Darth Vader just boarded the ship”);<br>$logger-&gt;emergency(“Bulb jammed in the ladies room”);<br> <br><strong>// Good</strong><br>$logger-&gt;emergency(“Darth Vader just boarded the ship”);<br>$logger-&gt;debug(“Bulb jammed in the ladies room”);</pre><h4>Id is for l33t</h4><p>Try to stuff your log messages with granular information when available.</p><pre><strong>// Not that bad, but…</strong><br>$logger-&gt;debug(“Tie just fired”);<br><strong>// MF - Tie just fired</strong></pre><pre><strong>// …Better</strong><br>$logger-&gt;debug(“Tie:$tieId just fired”);<br><strong>// MF - Tie:2 just fired</strong><br><strong>// Han — Chewie, target that second Tie!</strong></pre><p>If your language allows such nonsense like __toString, time to use it:</p><pre>class Tie {<br>    function __toString(){return __CLASS__.’:’.2;}<br>}<br> <br>$tie = new Tie();<br>$logger-&gt;debug(“$tie just fired”);<br><strong>// MF - Tie:2 just fired</strong></pre><h4>Production var_dump</h4><p>Avoid dumping big objects in the logs. See guzzle where the Exception only dumps the <a href="https://github.com/guzzle/guzzle/blob/master/src/Exception/RequestException.php#L128">first 120 chars</a> of the Request.</p><pre><strong>// Bad</strong><br>$logger-&gt;debug(var_export($darkStarTrooperCollection, true));</pre><pre><strong>// Good</strong><br>$logger-&gt;debug(“Current count of troopers on the darkstar is “.count($darkStarTrooperCollection));</pre><h4>Logging superstructure</h4><p>Don’t go raw file logging. You need something that aggregates your logs into one single accessible place, with powerful search and analysis tools. Since Logstash and Kibana ship in Docker containers, you really have no excuses to avoid this. If you don’t know about them, I strongly suggest having a <a href="https://www.elastic.co/webinars/introduction-elk-stack">look at it</a>.</p><p>A good logging harness will help you too. Add helpers everywhere and make sure everyone understands it (and reads this article). For php, you can use the classic but unmissable <a href="https://packagist.org/packages/monolog/monolog">monolog</a>.</p><p>Most logging harnesses can add metadata to log entries. Logstash understands the <strong>type</strong> field for example, to filter/transform log entries.</p><p>And you, have you been seeing weird log entries on your ship ? Have Corellians written a piece of code for your company ? I’d love to hear a good logging story from you !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d5097a547d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>