Acme-CPANModulesBundle-Import-PerlDancerAdvent-2018

 view release on metacpan or  search on metacpan

devdata/http_advent.perldancer.org_2018_23  view on Meta::CPAN

can spot it easily, without having to change your code (or your added debugging log statements). Instead,
you can put a regular expression into your configuration file.</p>
<pre class="prettyprint"># config.yml
engines:
  logger:
    Console::Colored:
      colored_regex:
       - re: "customer number \d+"
         color: "bold red"</pre>

<p>This will find customer numbers according to the pattern and make them bold and red. You can supply
a regular expression pattern and a color setting.</p>
<img src="/images/2018/23/log-2.png">

<p>Note that there is a list under the <code>colored_regex</code> key. This means you can actually have
multiple patterns. Even really simple ones that make <code>print</code> style debugging easy
and attractive.</p>
<pre class="prettyprint"># config.yml
engines:
  logger:
    Console::Colored:
      colored_regex:
       - re: "customer number \d+"
         color: "bold red"
       - re: "\bhere\b"
         color: "white on_green"</pre>

<p>If you want to highlight an entire log message in a specific color, you can set a pattern that captures
everything. However, this works on the message only, and not on the entire formatted line of log output.
(Patches welcome!)</p>
<pre class="prettyprint"># config.yml
engines:
  logger:
    Console::Colored:
      colored_regex:
        - re: ".+here.+"
          color: "white on_red"</pre>

<img src="/images/2018/23/log-3.png">

<p>This opens up a lot of possibilities, for debugging as well as for general logging during development.</p>
<h2><a name="what_else"></a>What else?</h2>

<p>There are still some feature ideas in the backlog, but it's already pretty useful. If you would
like to see additional features, please feel free to
[open an issue on github](https://github.com/simbabque/Dancer2-Logger-Console-Colored/issues).</p>
<p>And if you happen to use Mojolicious as well and need something similar, take a look at
<a href="https://metacpan.org/module/Mojo::Log::Colored">Mojo::Log::Colored</a>, which is in the early stages of development, but works quite well.</p>
<h2><a name="author"></a>Author</h2>

<p>This article has been written by Julien Fiegehenn (simbabque) for the Perl Dancer 
Advent Calendar 2018.</p>
<h2><a name="copyright"></a>Copyright</h2>

<p>No copyright retained. Enjoy.</p>
</div>

 <div id="disqus_thread"></div>
    <script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'danceradvent'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>




</div>



<div id="footer">
Powered by the  
<a href="http://perldancer.org/" title="Perl Dancer - Perl web framework">
Dancer Perl web framework</a>
</div>
</div>


<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-25174467-2']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>
</html>



( run in 0.612 second using v1.01-cache-2.11-cpan-39bf76dae61 )