snipt

Ctrl+h for KB shortcuts

Perl

Log messages based on debug level in log4perl

1
2
3
4
5
6
# Cheap in non-debug mode!
if($logger->is_debug()) {
    for (@super_long_array) {
        $logger->debug("Element: $_\n");
    }
}
https://snipt.net/embed/9a99084454f780a291db54dacc334011/
/raw/9a99084454f780a291db54dacc334011/
9a99084454f780a291db54dacc334011
perl
Perl
6
2019-05-26T20:24:12
True
False
False
/api/public/snipt/3810/
log-messages-based-on-debug-level-in-log4perl
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Cheap in non-debug mode!</span> </span><span id="L-2"><a name="L-2"></a><span class="k">if</span><span class="p">(</span><span class="nv">$logger</span><span class="o">-&gt;</span><span class="n">is_debug</span><span class="p">())</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">for</span> <span class="p">(</span><span class="nv">@super_long_array</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="nv">$logger</span><span class="o">-&gt;</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;Element: $_\n&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">}</span> </span><span id="L-6"><a name="L-6"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
perl